1 #include<stdio.h> 2 #include<math.h> 3 void view() 4 { 5 printf(" |---------------------------------------------| "); 6 printf(" | 单/复利计算 | "); 7 printf(" |---------------------------------------------| "); 8 printf(" |1.单利计算 | "); 9 printf(" |---------------------------------------------| "); 10 printf(" |2.复利计算 | "); 11 printf(" |---------------------------------------------| "); 12 printf(" |0.退出系统 | "); 13 printf(" |---------------------------------------------| "); 14 } 15 16 main() 17 { 18 int i,n,m; 19 double v,money; //本金 20 int years; //存钱年数 21 double sum; //存款总额 22 double r; //利率 23 while(1) 24 { 25 view(); 26 printf("请选择(0-2):"); 27 scanf("%d",&n); 28 switch(n) 29 { 30 case 1: 31 printf("请输入本金:"); 32 scanf("%lf",&money); 33 printf("请输入存钱年数:"); 34 scanf("%d",&years); 35 printf("请输入利率:"); 36 scanf("%lf",&r); 37 for(i = 1 ; i<=years; i++) 38 { 39 sum = r*i*money+money; 40 printf("存入第%d年后的存款总额为:%.2lf ",i,sum); 41 } 42 printf(" "); 43 break; 44 case 2: 45 printf("请选择: "); 46 printf("1.通过本金求存款总额 "); 47 printf("2.通过目标总额求本金 "); 48 scanf("%d",&m); 49 switch(m) 50 { 51 case 1: 52 printf("请输入本金:"); 53 scanf("%lf",&money); 54 printf("请输入存钱年数:"); 55 scanf("%d",&years); 56 printf("请输入利率:"); 57 scanf("%lf",&r); 58 for(i = 1 ; i<=years; i++) 59 { 60 v=pow(1+r,i); 61 sum = v*money; 62 printf("存入第%d年后的存款总额为:%.2lf ",i,sum); 63 } 64 printf(" "); 65 break; 66 case 2: 67 printf("请输入目标金钱:"); 68 scanf("%lf",&sum); 69 printf("请输入存钱年数:"); 70 scanf("%d",&years); 71 printf("请输入利率:"); 72 scanf("%lf",&r); 73 for(i = 1 ; i<=years; i++) 74 { 75 v=pow(1+r,i); 76 } 77 money=sum/v; 78 printf("现在必须存入本金为:%.2lf ",money); 79 printf(" "); 80 break; 81 } 82 case 0: 83 return 0; 84 } 85 } 86 }
这个程序主要是进行单利和复利的计算,可以选择通过本金求以后的存款总额,也可以选择通过目标金额来求取本金