Program for auto number generator | Auto digit creator program | C++ program
Number can be generate by using 'rand' function.
We can generate number random and automatically by this method.
We can generate number random and automatically by this method.
These are followings things include in the program:
- # include <time.h> : This is the library file which is used to generate number.
- srand (time(NULL)); : This is the pre-define function for change the random number. If it is not include then only one number can be display.
- int n=rand()%20; : This is actual function for generate number, % 20 is the rang from which program can generate number (such as number can choose from 0 to 20)
- n : at the end we can print value of n
Program start here:
# include <iostream>
# include <time.h> // this library is used for do this random number generator
using namespace std;
void main ()
{
//program for auto generated numbers
srand
(time(NULL)); //this
function must write before the 'rand' function
int n=rand()%20; // here 20
is the rang from which the program choose random number
cout<<"Random number are: "<<n<<endl;
}
Comments
Post a Comment