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;
}
|
|
Total comments: 0 | |