This code is supposed to find the total of all integers
in an array. Find all the errors you can:
int total;
int a = {1, 2, 4, 9, 16, 25, 36};
for(i = 1; i <= a.Length; i++);
{
total =+ a(i);
}
Ans:
- total should be initialized to 0.
- int a should be declared as int[ ] a.
- The for loop should go from 0 to a.Length - 1
instead of 1 to a.Length.
- =+ should be +=.
- a(i) should be a[i].