+ 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

6th Nov 2016, 1:31 PM
Sri Harsha Molleti
Sri Harsha Molleti - avatar
1 Answer
+ 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; }
6th Nov 2016, 2:53 PM
kamal joshi
kamal joshi - avatar