This is a short program to compute and print the squares of the numbers from 1 to 5. It's simple enough, so what's wrong?
1 /************************************************
2 * squares -- Print the squares of the numbers *
3 * from 1 to 5. *
4 ************************************************/
5 #include <iostream>
6
7 int main()
8 {
9 // An array for the squares
10 int array[5];
11
12 int i; // Index into the array
13
14 for (i = 1; i <= 5; ++i) {
15 array[i] = i*i;
16 }
17
18 for (i = 1; i <= 5; ++i) {
19 std::cout << i << " squared is " <<
20 array[i] << '\n';
21 }
22 return (0);
23 }