编一个程序,输入10个整数,统计并输出其中正数、负数和零的个数。要求用C语言编程。

如题所述

#include<stdio.h>
main()
{
int t,i,c0=0,c1=0,c2=0;
for(i=0;i<10;i++)
{
scanf("%d",&t);
if(t<0)c1++;
else if(t==0)c0++;
else c2++;
}
printf("正数个数 %d\n负数个数 %d\n零的个数 %d\n",c2,c1,c0);
getch();
return 0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-02-27
#include<stdio.h>
main()
{
int t,i,c0=0,c1=0,c2=0;
for(i=0;i<10;i++)
{
scanf("%d",&t);
if(t<0)c1++;
else if(t==0)c0++;
else c2++;
}
printf("正数个数 %d\n负数个数 %d\n零的个数 %d\n",c2,c1,c0);
getch();
return 0;
}本回答被提问者和网友采纳
第2个回答  2010-09-19
#include<stdio.h>
main()
{
int i,x=0,y=0,z=0,a[10];
for(i=0;i<10;i++) scanf("%d",&a[i]);
for(i=0;i<10;i++)
{
if(a[i]>0) x++;
else if(a[i]=0) y++;
else z++;
}
printf("%d %d %d\n",x,y,z);
}
说明:输出的x y z是正数、零、负数的个数
相似回答