arungo 2022-06-04 11:15 采纳率: 100%
浏览 202
已结题

关于PTA的问题,如何解决?

问题遇到的现象和发生背景

img

问题相关代码,请勿粘贴截图

函数接口定义:

double m_tax(double salary,int month);//计算每月累计应纳税额

函数返回每月累计应纳税额;
裁判测试程序样例:

#include<stdio.h>

double m_tax(double salary,int month);

int main()
{
    double money,tax,sum=0;
    int i;
    for(i=1;i<=12;i++)
    {
        scanf("%lf",&money);
        sum+=money;
        tax=m_tax(money,i);
        printf("the sum of %d months tax is %.2f\n",i,tax);
    }
    return 0;
}
/* 请在这里填写答案 */


我想要达到的结果

img

img

img

  • 写回答

3条回答 默认 最新

  • 白驹_过隙 新星创作者: 算法与数据结构技术领域 2022-06-04 14:00
    关注
    
    double sum=0;
    double m_tax(double salary,int month)
    {
        double s,tax;
        sum+=salary;
        if(sum<=month*5000)
            tax=0;
        else
        {
            s=sum-month*5000;
            if(s<=36000)
                tax=s*0.03;
            else if(s<=144000)
                tax=s*0.1-2520;
            else if(s<=300000)
                tax=s*0.2-16910;
            else if(s<=420000)
                tax=s*0.25-31920;
            else if(s<=660000)
                tax=s*0.30-52920;
            else if(s<=960000)
                tax=s*0.35-85920;
            else
                tax=sum*0.45-181920;
        }
        return tax;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 6月12日
  • 已采纳回答 6月4日
  • 创建了问题 6月4日