2.6
/*****输入贷款本集和月利率,输出还款年限-越还款额表*****/month
/*****公式money=loan*rate(1+rate)
/(1+rate)month
-1*****/
#include<stdio.h> #include<math.h> /* 程序中调用了数学函数,须包含头文件math.h*/
int main(void) { int year,month; double loan,rate,money; printf("Enter loan:"); /*输入提示*/ scanf("%lf",&loan); printf("Enter rate:"); scanf("%lf",&rate); month=1;
for(year=5;year<=30;year++){ month=12*year; money=loan*rate*pow((1+rate),month)/((1+rate,month)-1); printf("%d",year); printf("%.2f",money); } return 0; }