xxxxxxxxxx
#include<iostream>
#include<cstdlib>
#include
using namespace std;
main() {
int max;
max = 100; //set the upper bound to generate the random number
srand(time(0));
cout << "The random number is: "<<rand()%max;
}
xxxxxxxxxx
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main() {
srand(time(NULL) );
const char arrayNum[7] = {'0', '1', '2', '3', '4', '5', '6'};
int RandIndex = rand() % 7;
cout<<RandIndex<<endl;
return 0;
}
xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
int sz;
cout<<"Enter the size of array::";
cin>>sz;
int randArray[sz];
for(int i=0;i<sz;i++)
randArray[i]=rand()%100; //Generate number between 0 to 99
cout<<"\nElements of the array::"<<endl;
for(int i=0;i<sz;i++)
cout<<"Elements no "<<i+1<<"::"<<randArray[i]<<endl;
return 0;
}
xxxxxxxxxx
int i=rand()%10;
cout<<"Random number::"<<i<<endl;
Output::
Random number::6