首页 > 代码库 > 数值统计
数值统计
Problem Description
统计给定的n个数中,负数、零和正数的个数。
Input
输入数据有多组,每组占一行,每行的第一个数是整数n(n<100),表示需要统计的数值的个数,然后是n个实数;如果n=0,则表示输入结束,该行不做处理。
Output
对于每组输入数据,输出一行a,b和c,分别表示给定的数据中负数、零和正数的个数。
Sample Input
6 0 1 2 3 -1 0
5 1 2 3 4 0.5
0
Sample Output
1 2 3
0 0 5
code:
#include<stdio.h>
int main()
{
int n,i;
double m;
while(scanf("%d",&n)!=EOF)
{
int a=0,b=0,c=0;
if(n!=0)
{
for(i=0;i<n;i++)
{
scanf("%lf",&m);
if(m<0) a=a+1;
if(m==0) b=b+1;
if(m>0) c=c+1;
}
}
else
break;
printf("%d %d %d\n",a,b,c);
}
return 0;
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。