In: Computer Science
Please answer with code for C language
Problem: Counting Numbers
Write a program that keeps taking integers until the user enters -100.
In the end, the program should display the count of positive, negative (excluding that -100) and zeros entered.
Sample Input/Output 1:
Input the number:
0
2
3
-9
-6
-4
-100
Number of positive numbers: 2
Number of Negative numbers: 3
Number of Zero: 1
#include<stdio.h>
int main(){
int a,pos=0,nev=0,zero=0;
printf("Input the number:\n");
scanf("%d",&a);
while(a!=-100){
if(a==0){
zero++;
scanf("%d",&a);
}
else if(a<0){
nev++;
scanf("%d",&a);
}
else{
pos++;
scanf("%d",&a);
}
}
printf("Number of positive numbers: %d\n",pos);
printf("Number of Negative numbers: %d\n",nev);
printf("Number of Zero: %d",zero);
return 0;
}
Output: