#include <iostream>
usingnamespace std;
int main()
{
int array[10];
int sum = 0;
for ( int i = 0 ; i <= 10 ; ++i )
{
cout<<"Enter the value of the array with index "<<i<<" : ";
cin>>array[i];
sum += array[i];
}
cout<<"\nThe sum of array elements is: \n";
cout<<sum<<endl;
int k;
cin>>k;
return 0;
}
for ( int i = 0 ; i <= 10 ; ++i )
{
cout<<"Enter the value of the array with index "<<i<<" : ";
cin>>array[i];
if ( array[i] >= 10 )
{
sum += array[i];
}
}
int k;
cin>>k; why did you declare another variable?
That bit is forcing the user to enter something before the program exits. It's a way of pausing the program.
Presumably, the way Uk Marine runs code, it runs in an IDE that displays a temporary console window and then destroys the window once the program exits, so this is a way of pausing it before it exits.
and in arrays how did the program know sum process?
I'm not sure I understand your question. The sum is repeatedly updated for each value of i here: