1 #include<math.h> 2 #include<stdio.h> 3 #include<stdlib.h> 4 int a; 5 double principal; 6 float interest; 7 int year; 8 double finalValue; 9 double temp; 10 void simple() 11 { 12 printf("------------单利计算------------"); 13 printf("\n本金:"); 14 scanf("%lf",&principal); 15 printf("利率:"); 16 scanf("%f",&interest); 17 printf("年限:"); 18 scanf("%d",&year); 19 finalValue = principal * (interest * year +1); 20 printf("\n本息 = %lf",finalValue); 21 printf("\n"); 22 printf("\n"); 23 } 24 void compound() 25 { 26 printf("------------复利计算------------"); 27 printf("\n本金:"); 28 scanf("%lf",&principal); 29 printf("利率:"); 30 scanf("%f",&interest); 31 printf("年限:"); 32 scanf("%d",&year); 33 finalValue = principal * pow(interest + 1,year); 34 printf("\n本息 = %lf",finalValue); 35 printf("\n"); 36 printf("\n"); 37 } 38 void principalCalc() 39 { 40 printf("------------本金计算------------"); 41 printf("\n本息:"); 42 scanf("%lf",&principal); 43 printf("利率:"); 44 scanf("%f",&interest); 45 printf("年限:"); 46 scanf("%d",&year); 47 principal = finalValue / pow(interest + 1,year); 48 printf("\n本金 = %lf",finalValue); 49 printf("\n"); 50 printf("\n"); 51 } 52 void time() 53 { 54 printf("------------时间计算------------"); 55 printf("\n本金:"); 56 scanf("%lf",&principal); 57 printf("利率:"); 58 scanf("%f",&interest); 59 printf("本息:"); 60 scanf("%lf",&finalValue); 61 year = 1; 62 while(1) 63 { 64 temp = principal * pow(interest + 1,year); 65 if(temp>=finalValue) 66 break; 67 year++; 68 } 69 printf("\n时间 = %d",year); 70 printf("\n"); 71 printf("\n"); 72 } 73 void interestCalc() 74 { 75 printf("------------利率计算------------"); 76 printf("\n本金:"); 77 scanf("%lf",&principal); 78 printf("年限:"); 79 scanf("%d",&year); 80 printf("本息:"); 81 scanf("%lf",&finalValue); 82 interest = (float)pow(finalValue / principal,1 / (float)year) - 1; 83 printf("\n利息 = %f",interest); 84 printf("\n"); 85 printf("\n"); 86 } 87 void main() 88 { 89 system("mode con cols=32 lines=16"); 90 printf("-----------超级计算器-----------"); 91 printf("\n1、单利计算"); 92 printf("\n2、复利计算"); 93 printf("\n3、本金计算"); 94 printf("\n4、时间计算"); 95 printf("\n5、利率计算"); 96 printf("\n"); 97 printf("\n计算类型:"); 98 scanf("%d",&a); 99 system("cls"); 100 switch(a) 101 { 102 case 1: 103 simple(); 104 break; 105 case 2: 106 compound(); 107 break; 108 case 3: 109 principalCalc(); 110 break; 111 case 4: 112 time(); 113 break; 114 case 5: 115 interestCalc(); 116 break; 117 } 118 }