Design a program that will print 7 random numbers using the while looping statement and modulo operator.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
// Initializing random number generator in C++
srand(time(0));
cout<<"Seven Random numbers between 1 and 20:"<<endl;
int x = 0; /* <<< Initialization */
while(x < 7)
{
cout << 1+ (rand() %20) <<"\n";
x++;
}
return 0;
}
Comments
Leave a comment