首页 文章详情

poj 1004 Financial Management

C语言题库 | 368 2021-10-12 13:22 0 0 0
UniSMS (合一短信)

Financial Management

Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 227839
Accepted: 85083

Description

Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Larry has decided that he needs to grab hold of his financial portfolio and solve his financing problems. The first step is to figure out what's been going on with his money. Larry has his bank account statements and wants to see how much money he has. Help Larry by writing a program to take his closing balance from each of the past twelve months and calculate his average account balance.

Input

The input will be twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.

Output

The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be no other spaces or characters in the output.

Sample Input

100.00
489.12
12454.12
1234.10
823.05
109.20
5.27
1542.25
839.18
83.99
1295.01
1.75

Sample Output

$1581.42



财务管理


描述

拉里今年毕业了,终于找到了一份工作。他赚了很多钱,但不知怎么的,似乎总是不够。拉里决定,他需要抓住他的金融投资组合,解决他的融资问题。第一步是弄清楚他的钱到底花在哪里了。拉里有他的银行账户对账单,想看看他有多少钱。帮拉里写一个程序,从他过去12个月的期末余额中计算出他的平均账户余额。


输入

输入将是12行。每一行都将包含某一个月他的银行账户的期末余额。每个数字都是正数,并显示给硬币。不包括美元符号。


输出

输出将是一个数字,即12个月期末余额的平均值。它会四舍五入到最近的便士,前面马上有一个美元符号,然后是行尾。输出中将没有其他空格或字符。


Sample Input

100.00
489.12
12454.12
1234.10
823.05
109.20
5.27
1542.25
839.18
83.99
1295.01
1.75

Sample Output

$1581.42



解题思路: 

求平均数


代码:

#include<stdio.h>
int main()
{
double x, sum = 0;
int i;
for(i = 0; i < 12; i++)
{
scanf("%lf", &x); //输入一定要用%lf
sum += x;
}
printf("$%.2f\n", (double)sum / 12);
return 0;
}


good-icon 0
favorite-icon 0
收藏
回复数量: 0
    暂无评论~~
    Ctrl+Enter