[Poj1004]Financial Management

来源:互联网 发布:net域名后缀排名高吗 编辑:程序博客网 时间:2024/04/24 16:38

  新人来了,先水一道PKU上的大水题吧。。。


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.


  思路:没什么好说的,真的是很水。无非是循环一遍读入及求和,最后取平均数。。。

  就是要注意使用double类型。。。

#include<iostream>#include<iomanip>using namespace std;double a[13],sum,ans;int main(){int i;sum=0;for(i=1;i<=12;i++){cin>>a[i];sum+=a[i];}ans=sum/12.0;cout<<"$";cout<<fixed<<setprecision(2)<<ans<<endl;}


1 0
原创粉丝点击