27: 统计整数

27 统计整数

作者: 江宝钏 时间限制: 1S 章节: 循环

问题描述 :
从键盘输入任意20个整数,统计其中的负数个数,并求所有整数的平均值。

输入说明 :
20个整数

输出说明 :
负数个数和整数平均值(保留1位小数)

输入范例 :
1 2 3 4 5 6 7 8 9 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 0
输出范例 :
9 0.0
代码:

#include <stdio.h>
int main()
{
	int n,num = 0, sum = 0;
	double ave;
	for (int i = 0; i < 20; i++)
	{
		scanf("%d", &n);
		if (n < 0)
		{
			num++;
		}
		sum += n;
	}
	ave = (double)sum / 20.0;
	printf("%d %.1lf", num, ave);
	return 0;
}
Yesterday is history,tomorrow ismystery,but today is a gift!That why it is called Present!
原文地址:https://www.cnblogs.com/VictorierJwr/p/12248862.html