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.
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