// arrays example
#include <iostream>
usingnamespace std;
int billy [] = {16, 2, 77, 40, 12071};
int n, result=0;
int main ()
{
for ( n=0 ; n<5 ; n++ )
{
result += billy[n];
}
cout << result;
return 0;
}
Here is your program written in a more "beginner programmer-friendly" way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int main ()
{
int billy[] = { 16, 2, 77, 40, 12071 };
int result = 0;
for (int i = 0; i < 5; i++)
{
result = result + billy[i];
}
cout << result;
return 0;
}