0:07 AM 2011-2012 question 1 |
write a program using while statement and conditional operator to read n integer values and calculate
1- number and sum of negative values 2- number and sum of positive values
#include<stdio.h>
main()
{
int val, n, i=1, pos=0, neg=0, poss=0, negs=0;
printf("enter the number of integers values : ");
scanf("%d", &n);
while(i<=n){
printf("enter value no. %d : ", i);
scanf("%d", &val);
val<=0 ? neg++, negs+=-val : pos++, poss+=val ;
i++;
}
printf("number of positives : %d , sum of positives : %d", pos, poss);
printf("\nnumber of negatives : %d , sum of negatives : %d", neg, negs);
getch();
return 0;
}
|
|
Total comments: 0 | |