关于教育孩子的方法:麻烦用c语言编写下面的程序!!!

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/30 02:59:02
输入20个有符号的整数,统计正整数、零、负整数的个数

#include<stdio.h>
void main()
{
int x=0,o=0,y=0,i,a[20];//x zheng shu,o ling,y fu shu,a[20] cun 20 ge shu,i ji shu qi
printf("Shu ru 20 ge zheng shu:\n");
for(i=0;i<20;i++)
{
printf("Di %d ge shu:",(i+1));
scanf("%d",&a[i]);
if(a[i]>0)
x++;
else
if(a[i]==0)
o++;
else
y++;
}
printf("Zheng shu wei:%d\nLing wei:%d\nFu shu wei:%d",x,o,y);
}

#include <stdio.h>
#define num 20

int main (int argc, char *argv[])
{
int input_array[num];
int i=0;
int positive=0, negtive=0, zero=0;
printf("%s%d%s","Input ", num, " Integers: ");
for (i=0; i<num; i++)
{
scanf("%d",&input_array[i]);
if(input_array[i] > 0)
positive++;
else if (input_array[i] < 0)
negtive++;
else
zero++;
}

printf("%s%d\n","The number of positive Integer: ",positive);
printf("%s%d\n","The number of negtive Integer: ",negtive);
printf("%s%d\n","The number of zero: ",zero);
return 0;
}