天天看點

0312複利計算3

1、建立功能菜單以及相關的提示

2、代碼功能有單利計算利息和和根據利息和求相應的本金

3、代碼功能有複利計算利息和和根據利息和求相應的本金

4、退出系統功能

#include<stdio.h>

#include<math.h>

int year,n;

double p,q,F=0.0;

void innit()

{

printf("注釋:p為現金\n");

printf(" year為年限\n");

printf(" n為年複利次數\n");

printf(" q為年利率\n");

printf(" F為年複利終值\n");

}

void menu()

printf("\t|------------------------------------|\n");

printf("\t| welcome |\n");

printf("\t| 1、複利計算 |\n");

printf("\t| 2、單利計算 |\n");

printf("\t| 0、退出系統 |\n");

void compoundinterest(){

int I;

int ch;

B:printf("\t1、擷取複利終值\n");

printf("\t2、根據複利終值擷取本金\n");

printf("請選擇功能:");

scanf("%d",&I);

if(I==1)

printf("請輸入存款金額:");

scanf("%lf",&p);

printf("請輸入存入存蓄年限:");

scanf("%d",&year);

printf("請輸入年複利次數:");

scanf("%d",&n);

printf("請輸入年利率:");

scanf("%lf",&q);

F=p*pow((1+q/n),year*n);

printf("複利終值為%lf:",F);

if(I==2)

printf("請輸入複利終值:");

scanf("%lf",&F);

p=F/(pow((1+q/n),year*n));

printf("複利終值為%lf:",p);

printf("\n\t是否要重新計算?(1/0)\n");

scanf("%d",&ch);

if(ch==1)

goto B;

void simpleinterest()

int n;

A:printf("\t1、擷取單利終值\n");

printf("\t2、根據單利終值擷取本金\n");

if(n==1)

F=p*(1+q*year);

printf("單利終值為%lf\n:",F);}

if(n==2)

printf("請輸入單複利終值:");

p=F/(1+q*year);

printf("本金為%lf\n:",p);}

goto A;

}}

main(){

int ch,n;

while(1){

if(n==0) break;

innit();

menu();

printf("please chose:");

switch(ch){

case 1:compoundinterest();break;

case 2:simpleinterest();break;

case 0:n=0;break;

}}}

單利計算求利息和:

0312複利計算3

單利計算根據利息和求本金:

0312複利計算3