171k views
5 votes
What is output?

C = 1
Sum = 0
while (c less than 10):
C = c + 3
sum = sum + c
print (sum)

1 Answer

7 votes

Answer:

The output of code will be 10

Step-by-step explanation:

We need to find output of following code:

C = 1

Sum = 0

while (c less than 10):

C = c + 3

sum = sum + c

print (sum)

Solution:

We will check the condition of while loop, if the condition is true, then the statements inside the loop will be executed. Since brackets are not available so, only one statement is linked with while loop.

First while loop will be executed c < 10 (1<10) the condition becomes true, and statement c=c+3 will be executed ( 4=1+3) and then loop condition will be checked (4<10) the condition becomes true, and statement c=c+3 will be executed ( 7=4+3) and then loop condition will be checked (7<10) the condition becomes true and statement c=c+3 will be executed ( 10=7+3) and then loop condition will be checked (10<10) the condition becomes false, so we will come outside loop body and execute: sum=sum+c (10=0+10) and print sum i. e 10

So, The output of code will be 10

User PaperTsar
by
6.9k points