I understna dthis porgram and what it is explaing. but i dont unders stand the output it got. Like how did the output number come.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// 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<< endl;
system("PAUSE");
return 0;
}
OUTPUT>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
12206
Press an key to continue...
You have an array of integers named 'billy'. The for loop goes through the array, adding the value found at each position in the array to the value of the variable 'result'. In other words:
result = 0
billy[0] = 16
result += billy[0] (result = 16)
billy[1] = 2
result += billy[1] (result = 18)
billy[2] = 77
result += billy[2] (result = 95)
...
The loop stops when 'n' becomes 5 because the condition for continuing the loop is "n<5". Obviously 5 is not less than 5 (it is equal), so the loop exits. The final value of 'result' is outputted to the screen.