计算利息,for使用范例

/*利息计算程序,for使用范例*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void)
{
double amount;/*存款总额*/
double principal=1000.0;/*初始本金*/
double rate=0.05;/*年利率*/
int year;/*储蓄年份*/
printf("\nWelcome.\n"
"Calculate the compound interest\n\n");
for(year=1;year<=10;year++)
{
amount=principal*pow(1.0+rate,year);
printf("%4d%21.2f\n",year,amount);
}/*end for*/
system("PAUSE");
return 0;
} /*end main*/

posted @ 2017-03-22 20:24  HGR  阅读(229)  评论(0编辑  收藏  举报