C++
Programming and Technical
undefined
Pankaj makes a program to print the product of cubes of the first 10 whole numbers.
She writes the following program:
integer x = 0 // statement 1
integer x = 0 // statement 1
integer sum = 0 // statement 2
while ( x < 10 ) // statement 3
{
sum = x*x*x // statement 4
x = x + 1 // statement 5
}
print sum // statement 6
Is her program correct? If not, which statement will you modify to correct it?
a. No error, the program is correct
b. Statement 1
c. Statement 4
d. statement 6
Read Solution (Total 9)
-
- Statement 4 is incorrect
because in the above program we have to print product of cubes of the first 10 whole numbers but according to the above program it gives the output of only the cube of first of first 10 numbers not the product of them So for this Statement 4 should be :
sum = sum*(x*x*x)
- 8 years agoHelpfull: Yes(6) No(7)
- Product of cubes doesn't make any sense.
This might be sum of the cubes of first 10 whole nos, since thrz a variable sum.
And why is
So lets modify statement 4
sum=sum+x*x*x
otherwise, if its the product of cubes then multiples lines have to be modified. - 8 years agoHelpfull: Yes(5) No(1)
- The value of the cube of is being assigned in the loop, rather it should be the sum of the Cube as Answered by the other fellows
- 8 years agoHelpfull: Yes(1) No(1)
- statement 6 i.e option 4 will be the ans.
bcoz print is outside the loop ,it should be inside. - 6 years agoHelpfull: Yes(1) No(1)
- statement 1
- 7 years agoHelpfull: Yes(0) No(2)
- a. No error, the program is correct
- 6 years agoHelpfull: Yes(0) No(3)
- a is answer.
As in question its asked for whole number which start with 0, so anything multiplied with 0 will result in 0 as result. - 5 years agoHelpfull: Yes(0) No(1)
- complete the question `->` the first line of this question is ` ->` "Pankaj makes a program to print the product of cubes of the first 10 whole numbers She writes the following program:"
now according to the question, the correct answer is::
to print the cubes of all no. less than 10, statement 6 should be within a while loop. so statement 6 is wrong
OPTION D. - 4 years agoHelpfull: Yes(0) No(0)
- c the statement should be sum = sum + x*x*x
- 3 years agoHelpfull: Yes(0) No(0)
C++ Other Question