Hey , i need to create a program that has has an array size of 20 and will generate 20 random numbers in it between 1-1000. Then I need to calculate the average of all the random numbers.
I have half of the code done ,but im lost on how to calculate the average of the random numbers.
And also could you please point out any way to help shorten my coding that will be helpfull :D
Here what I have:
//Assignment 17 Program 2
#include <iostream>
usingnamespace std;
int i;
int size[20];
int counter = 0;
int main()
{
cout << "The Array Consists Of 20 Random Numbers: "<<endl<<endl;
//Random Numbers Generator
srand ( time(NULL) );
for (int j = 1;j<20;j++)
{
i = rand() % 1001;
if (i != i-1)
size[j]=i;
else
{
i = rand() % 1001;
size[j]=i;
}
}
for (int k = 1; k < 20 ; k++)
{
cout << size[k] << " "<<endl<<endl;
}
//Average Of Random Generated Numbers
system ("pause");
return 0;
}