What is the output of the following program?
#include<stdio.h>
int c[10] = {1,2,3,4,5,6,7,8,9,10};
main()
{
int a, b=0;
for(a=0;a<10;++a)
if(c[a]%2 == 1)
b+=c[a];
printf("%d", b);
}
#include<stdio.h>
int c[10] = {1,2,3,4,5,6,7,8,9,10};
main()
{
int a, b=0;
for(a=0;a<10;++a)
if(c[a]%2 == 1)
b+=c[a];
printf("%d", b);
}
A. 20
B. 24
C. 25
D. 30
E. None of these
Answer: Option C
Solution(By Examveda Team)
Condition if(c[a]%2 == 1) forces only odd numbers to add in the sum.
Join The Discussion
Comments ( 3 )
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
length=int(input("Enter the length of the cuboid:"))
width=int(input("Enter the width of the cuboid:"))
height=int(input("Enter the height of the cuboid:"))
s_area=2*((length*width)+(length*height)+(width*height))
volume=length*width*height
print("Surface Area of Cuboid =", s_area)
print("Volume of cuboid=", volume)
you have a loop up to 10 so after reaching to 10 if has semicolon so loop is terminated and ++a makes a=11
now now 11%2 means 11
so if condition is 11==1 we have to take skip one number as we start from 1 we have to skip 2 then had 3 after that skip 4 by this add all the odd numbers up to loop 10 thus, 1+3+5+7+9 = 25 that is why c is the answer
IM NOT UNDERSTAND THIS QUESTION... please give deep expalination