[My site ]
Main » 2013 » December » 12 » 2009-2010 question 1
11:53 PM
2009-2010 question 1
write a program using while statement and conditional operator to read n integer values and calculate 
1- number and sum of odd values
2- number and sum of even values


#include<stdio.h>
main()
{
int val, n, i=1, odd=0, even=0, odds=0, evens=0;

printf("enter the number of integers values : ");
scanf("%d", &n);

while(i<=n){
printf("enter value no. %d : ", i);
scanf("%d", &val);

val%2==0 ? even++, evens+=val : odd++, odds+=val ;

i++;
}

printf("number of odds : %d , sum of odds : %d", odd, odds);
printf("\nnumber of evens : %d , sum of evens : %d", even, evens);

getch();
return 0;
}



Category: C Programming - 1 | Views: 352 | Added by: ahansaary | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Sign Up | Login ]