我最近发现数组对于初学者较难理解,所以发布了一些不是数组的方法,供大家参考
题目描述
统计在所输入的N个整数中有多少个正数、多少个负数、多少个零。
输入要求
先输入一个整数N,接着输入这N个整数。
输出要求
按顺序输出正数,负数,零的个数。输出各占一行。个数为0的项目也要输出。
输入样例
20 -5 0 2 6 8 4 2 1 3 6 9 84 0 2 6 -6 -6 -9 63 5
输出样例
14 4 2
#include<stdio.h>
int main()
{
int b=0,i=0,a=1,c=0,n,e,d=0;
scanf("%d",&e);
while(a<=e){
scanf("%d",&n);
if(n>0){
b++;
a++;
}
else if(n<0){
c++;
a++;
}
else{
d++;
a++;
}
}
printf("%d\n",b);
printf("%d\n",c);
printf("%d\n",d);
return 0;
}