Hi,
I am trying to generate an array of n random numbers. The following program runs fine for n<5. But when n equals or greater than 5, the code gives me Segmentation fault. Please, help me figure out whats wrong with code.
/* Generate an array of n random numbers */
#include <iostream>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main ()
{
int n, A[n];
srand ((unsigned)time(0));
cout << "Enter the size of array for random numbers: ";
cin >> n;
for (int i=0; i<n; i++){
A[i]=(rand() % 1000) +1;
cout << A[i] << " ";
}
cout << endl;
return 0;
}