Question discussion

What is the output of the following program?#includeint c[10] = {1,2,3,4,5,6,7,8,9,10}; main(){ int a, b=0; for(a=0;a

305300Medium 1 reply 1,857 views
0
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);}
  • A20
  • B24
  • C25
  • D30
  • ENone of these
Correct answer: C

Discussion 1

0
CCommunity
25

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