[My site ]
Main » 2013 » December » 13 » 2011-2012 question 1
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;
}
Category: C Programming - 1 | Views: 369 | Added by: ahansaary | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Sign Up | Login ]