zoukankan      html  css  js  c++  java
  • 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为现金 ");
    printf(" year为年限 ");
    printf(" n为年复利次数 ");
    printf(" q为年利率 ");
    printf(" F为年复利终值 ");
    }
    void menu()
    {
    printf(" |------------------------------------| ");
    printf(" | welcome | ");
    printf(" |------------------------------------| ");
    printf(" | 1、复利计算 | ");
    printf(" | 2、单利计算 | ");
    printf(" | 0、退出系统 | ");
    printf(" |------------------------------------| ");
    }
    void compoundinterest(){
    int I;
    int ch;
    B:printf(" 1、获取复利终值 ");
    printf(" 2、根据复利终值获取本金 ");
    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);
    printf("请输入存入存蓄年限:");
    scanf("%d",&year);
    printf("请输入年复利次数:");
    scanf("%d",&n);
    printf("请输入年利率:");
    scanf("%lf",&q);
    p=F/(pow((1+q/n),year*n));
    printf("复利终值为%lf:",p);
    }
    printf(" 是否要重新计算?(1/0) ");
    scanf("%d",&ch);
    if(ch==1)
    {
    goto B;
    }
    }
    void simpleinterest()
    {
    int n;
    int ch;
    A:printf(" 1、获取单利终值 ");
    printf(" 2、根据单利终值获取本金 ");
    printf("请选择功能:");
    scanf("%d",&n);
    if(n==1)
    {

    printf("请输入存款金额:");
    scanf("%lf",&p);
    printf("请输入存入存蓄年限:");
    scanf("%d",&year);
    printf("请输入年利率:");
    scanf("%lf",&q);

    F=p*(1+q*year);
    printf("单利终值为%lf :",F);}
    if(n==2)
    {
    printf("请输入单复利终值:");
    scanf("%lf",&F);
    printf("请输入存入存蓄年限:");
    scanf("%d",&year);
    printf("请输入年利率:");
    scanf("%lf",&q);

    p=F/(1+q*year);
    printf("本金为%lf :",p);}
    printf(" 是否要重新计算?(1/0) ");
    scanf("%d",&ch);
    if(ch==1)
    {
    goto A;
    }}

    main(){
    int ch,n;
    while(1){
    if(n==0) break;
    innit();
    menu();
    printf("please chose:");
    scanf("%d",&ch);
    switch(ch){
    case 1:compoundinterest();break;
    case 2:simpleinterest();break;
    case 0:n=0;break;
    }}}

    单利计算求利息和:

    单利计算根据利息和求本金:

  • 相关阅读:
    html5 audio vedio and video.js
    webpack的require是如何工作的?
    webpack HMR是如何工作的?
    vuejs code splitting with webpack 3种模式
    how webpack Hot Module Replacement works
    C# checkedlistbox 控件 有bug
    C# DataGridView 更改类型 重绘
    C# webapi
    C# 遍历控件名称
    C# 转json
  • 原文地址:https://www.cnblogs.com/4249ken/p/5268700.html
Copyright © 2011-2022 走看看