This program generates and prints 10 random numbers between 0 and 9 using the rand() function.
The program contains a function randnum() which has a for loop that runs 10 times. In each iteration of the loop, a random number between 0 and 9 is generated using the rand() function and stored in the random variable. This number is then printed on the console using the cout statement.
In the main() function, the randnum() function is called to execute the code in the function. Finally, the function returns 0 to indicate successful program execution.
#include<iostream> using namespace std; void randnum() { int random; for(int i=0; i<10; i++) { random=rand()%10; cout<<random<<endl; } } int main() { randnum(); return 0; }
1 7 4 0 9 4 8 8 2 4To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions