int gen() //function
{
int x; //variable declared
return x; //return that variable
}
int main()
{
int array[20],i;
for(i=0;i<20;i++)
array[i]=gen(); //using for loop variables are generated and stored in an array
return 0; //however if you are going to store values in an array you don't need all those variables
}
Can also be done without function
1 2 3 4 5 6 7 8 9 10
int main()
{
int i,array[20];
int sum=0;
for(i=0;i<20;i++)
cin>>array[i];
for(i=0;i<20;i++)
sum+=array[i];
return 0;
}