C++大学基础教程_5_4for语句复制

#include <iostream>
using std::cin ;
using std::cout;
using std::endl;//嘿嘿,少了其中一个看看会有什么发生
using std::fixed;//将数字按指定的小数位数进行取整,利用句号和逗号以十进制格式
                       //对该数进行格式设置,并以文本形式返回结果
#include <cmath>
using std::pow;//幂运算函数
using std::exp;

#include <iomanip> 
using std::setw;//setw(int),里面的int的数值代表域宽的字符数
using std::setprecision;//控制输出流显示浮点数的数字个数,如果和fixed合用的话,
                                 //可以控制小数点右面的位数

//using namespace std;

int main()
{
	double  amount ;//计算利率后的存款总金额
	double principal = 1000.00; //初始存款金额
	double rate  = 0.05; //利率
	cout << "Year" << setw(20) << "Amount on deposit" << endl;
	cout << fixed  << setprecision(4) ;
	for(int year = 1;year<=10;year++)
	{
		amount = principal*pow(1.00+rate,year) ;
		cout << setw(4) << year << setw(20) << amount << endl;
	}
	double y = exp((double)2.00) ;
	cout << y ;
	
	system("pause >> cout ");
	return 0 ;
}

猜你喜欢

转载自jia-shun.iteye.com/blog/2064114