编程从键盘输入一个整数值K,再循环输入K个整数num,统计其中正数,零和负数的个
#include<stdio.h>
int main(){
int k=0, temp=0;
int a=0, b=0, c=0;
scanf("%d", &k);
while(k--){
scanf("%d", &temp);
if(temp>0)
a++;
else if(temp==0)
b++;
else
c++;
}
printf("正数:%d个\n零:%d个\n负数:%d个", a, b, c);
return 0;
}
int main(){
int k=0, temp=0;
int a=0, b=0, c=0;
scanf("%d", &k);
while(k--){
scanf("%d", &temp);
if(temp>0)
a++;
else if(temp==0)
b++;
else
c++;
}
printf("正数:%d个\n零:%d个\n负数:%d个", a, b, c);
return 0;
}
温馨提示:答案为网友推荐,仅供参考