Store five integers in an array and calculate the total.
a | b | c | d | e | declare by | int a, b, c, d, e; | ||
A[0] | A[1] | A[2] | A[3] | A[4] | declare by | int A[5]; | int [] A = new int[5]; | |
element | 7 | 6 | 8 | 4 | 3 | C++ | Java | |
index | 0 | 1 | 2 | 3 | 4 |
A
MATH WAY: total = A[0] + A[1] + A[2] + A[3] + A[4];
Computer Way:
total = 0;
total += A[0]; //total = total + A[0];
total += A[1]; //total = total + A[1];
total += A[2]; //total = total + A[2];
total += A[3]; //total = total + A[3];
total += A[4]; //total = total + A[4];
total = 0;
for(i = 0; i < 5; i++)
total += A[i];
Your work is to develop a program to have the following interface with user.