Choose the correct option.
The program to print the sum of all cubes that lie between 0 and 100 is
given below. Does this program have an error? If yes, which statement
should be modified to correct the program?
integer i = 0.a // Statement
integer sum = 0;
a = (
ii)
while (<100) // Statement 2
sum = sum + a // Statement 3
= -1
Statement 45
}
print sum
Answers
Answered by
120
This program has multiple errors. The statements to be corrected are statement 1, 2 and 4.
- integer i = 0,a // statement 1
- while (i<100) // statement 2
- i = i +1 // statement 4
- The correct program will be as follows;
integer i = 0,a // Statement 1
integer sum = 0;
a = ( i*i*i)
while (i<100) // Statement 2
sum = sum + a // Statement 3
i = i + 1 // Statement 4
a = i*i*i
}
print sum
Similar questions