C语言编写程序,从输入的整数中统计大于0和小于0的个数,用0作为结束输入的数据。。。求解。。。谢谢了。

如题所述

#include <stdio.h>

int main() {

int plus = 0,negative = 0,num;

while(1) {

printf("请输入 : ");

scanf("%d",&num);

if(num == 0) break;

if(num > 0) plus++;

else negative++;

}

printf("大于0的数是%d个\n",plus);

printf("小于0的数是%d个\n\n",negative);

return 0;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-07-11
#include<stdio.h>
void main()
{
int a[100] = {0}, i = 0, z=0, f=0, s;
printf("输入一个整数按回车进行下次输入\n");  
while (1)
{
scanf("%d",&a[i]);
if (a[i] == 0) { break; }
i++;
}
for (s = 0; s < i; s++)
{
if (a[s] < 0) { f = f + 1; }
if (a[s] > 0) { z = z + 1; }
}
printf("正数的个数有%d个\n负数的个数有%d个\n", z, f);
while (1);
}

本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网