poj1004
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
1 #include<stdio.h>
2 int main()
3 {
4 double a,sum=0;
5 int i;
6 for(i=0;i<12;i++)
7 {
8 scanf("%lf",&a);
9 sum+=a;
10 }
11 printf("$%.2f\n",sum/12.0);
12 return 0;
13 }
虽然我很菜,但是这道题未免太水了。。不过还是有要注意的地方:
一、跟poj1003一样,double类型的scanf格式用“%lf”,float的用“%f”,printf时都用“%f”,因为标准C的printf不能用“%lf”
这个我就不考证了,百度上有人说的~~
二、实数的小数位输出问题。。这个百度一下即可 反正我资格去比赛 用不着记这些~~
三、浮点数计算 定义时尽量用double 反正用float也要转化成double的~~
四、这题为嘛不用多次输入???没有标准的while哦。。