/*利息计算程序,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*/
时间: 2024-10-11 08:58:52