+ 1
Is there a way to assign these random numbers generated every time we run the program to different variables?
I mean random numbers generated should be stored in different variables for later use
1 Antwort
+ 2
You can array and assign random values to it like this:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(0));
int a[16];
for(int i=0;i<16;i++){
a[i] = rand()%4 + 1;
}
for(int i=0;i<16;i++){
cout<<"a["<<i<<"] = "<<a[i]<<endl;
}
return 0;
}