POJ 1004 浮点数运算水题

来源:互联网 发布:分享到qq好友js代码 编辑:程序博客网 时间:2024/06/05 09:05

URL:http://poj.org/problem?id=1004


题目大意:

给定12个浮点数,求它们的平均值,四舍五入至两位小数。


思路分析:

直接运算即可


部分易错点:

1. 勿忘添加"$"输出


代码呈现:

(Memory: 480K; Time: 0MS; Code: 221B)

#include<cstdio>using namespace std;int main(){    float x,n,m;    int i;    n = 0;    for(i=0; i<12; i++)    {        scanf("%f",&x);        n+=x;    }    m = n/12;    printf("$%.2f",m);    return 0;}