ExamVeda
Login
Home
This question belongs to C Program Control Structures
Control Structures
?

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);
}

Answer & Solution
Correct Answer: Option C

Condition if(c[a]%2 == 1) forces only odd numbers to add in the sum.

Examveda
Question posted by Examveda
Community

Join the Discussion

3 Comments
NEHAL DANGAYACH
NEHAL DANGAYACH 3 years ago
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)
Daniyal Ansari
Daniyal Ansari 6 years ago
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
KARTHI K
KARTHI K 9 years ago
IM NOT UNDERSTAND THIS QUESTION... please give deep expalination