Sum of Numbers

本文介绍了一个程序设计任务,该程序能够读取十个数,并分别计算所有正数、所有非正数及全部数字的总和。输入的数字可以任意顺序给出,且只需要输入一次。最终输出三个总和,每个总和保留两位小数。

Description

Write a program that reads in ten numbers and then outputs the sum of all positive numbers, the sum of all nonpositive numbers, and the sum of all the ten numbers. The user enters the ten numbers just once each and the user can enter them in any order. Your program should not ask the user to enter the positive numbers and the negative numbers separately.

Input

Ten numbers

Output

The sum of the numbers greater than zero, the sum of the numbers less than zero, and the sum of all numbers, seperated by commas. Each value output should be rounded to 2 digits after the decimal point.

Sample Input

2 3 -3 4 5 6 12 7 0 -5

Sample Output

39.00,-8.00,31.00

HINT

#include <cstdio>
int main()
{
	float a[10];
	while (scanf("%f",&a[0])!=EOF)
	{
		for (int i = 1; i < 10; i++)
			scanf("%f", &a[i]);
		float positive = 0, negative = 0, all = 0;
		for (int i = 0; i < 10; i++)
		{
			all += a[i];
			if (a[i] > 0)
				positive += a[i];
			else if (a[i] < 0)
				negative += a[i];
		}
		printf("%.2f,%.2f,%.2f\n", positive, negative, all);
	}
	return 0;
}



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值