?
What is the output of the following program?
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);
}
Answer & Solution
Correct Answer:
Option
C
Condition if(c[a]%2 == 1) forces only odd numbers to add in the sum.
Join the Discussion
Login to post a comment or share your explanation.
Loginwidth=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)
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