Consider the following program fragment:
for(c=1, sum=0; c <= 10; c++)
{
scanf("%d", &x);
if( x < 0 ) continue;
sum += x;
}
What would be the value of sum for the input 1, -1, 2, -2, 3, -3, 4, -4, 5, -5
for(c=1, sum=0; c <= 10; c++)
{
scanf("%d", &x);
if( x < 0 ) continue;
sum += x;
}
What would be the value of sum for the input 1, -1, 2, -2, 3, -3, 4, -4, 5, -5
A. -5
B. 30
C. 10
D. 1
E. 15
Answer: Option E
Solution(By Examveda Team)
It is summation of 1+2+3+4+5 as continue statement is going to be executed for every input of -1, -2, -3, -4, -5.
Which control structure is used to repeatedly execute a block of code in C?
A. for loop
B. if statement
C. switch case
D. while loop
In C, what is the purpose of the 'break' statement within a loop?
A. Continue to the next iteration
B. Exit the program
C. Terminate the loop and exit it
D. Skip the current iteration
What is the purpose of the 'else' statement in C's 'if-else' control structure?
A. Execute the 'if' block
B. Execute the 'else' block
C. Execute both 'if' and 'else' blocks
D. Skip the 'if' block
Which control structure is used to make a decision between two or more alternatives in C?
A. switch case
B. for loop
C. if statement
D. while loop
Join The Discussion