鱼C论坛

 找回密码
 立即注册
查看: 1539|回复: 2

[已解决]qzyx

[复制链接]
发表于 2023-11-16 14:53:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本题目要求读入每月工资,计算按月需要累计缴纳的税额(税率见下图),此处只需显示应缴纳的税额,无需减去已缴纳部分。结果保留两位小数。 注意:每月有5000元免税额。

1.png
上图为按年累计应纳税所得额

函数接口定义:
double m_tax(double salary,int month);
其中salary和 month 是用户传入的参数,函数返回每月累计应纳税额。

裁判测试程序样例:
#include<stdio.h>

double m_tax(double salary,int month);

int main()
{
    double money,tax;
    int i;
    for(i=1;i<=12;i++)
    {
        scanf("%lf",&money);
        tax=m_tax(money,i);
        printf("the sum of %d months tax is %.2f\n",i,tax);
    }
    return 0;
}
/* 请在这里填写答案 */
输入样例:
1000
2000
10000
5000
8000
500
2000
15000
1000
5000
6000
9000
输出样例:
在这里给出相应的输出。例如:

the sum of 1 months tax is 0.00
the sum of 2 months tax is 0.00
the sum of 3 months tax is 0.00
the sum of 4 months tax is 0.00
the sum of 5 months tax is 30.00
the sum of 6 months tax is 0.00
the sum of 7 months tax is 0.00
the sum of 8 months tax is 105.00
the sum of 9 months tax is 0.00
the sum of 10 months tax is 0.00
the sum of 11 months tax is 15.00
the sum of 12 months tax is 135.00
注意 :3月虽然工资为10000元,但3个月累计免税额为15000元,因此无需纳税。5月时累计免税额为25000元,累计工资收入为26000元,因此应纳税额为1000元,按税率为30元,后面同理所得。


这题用C语言怎么做
最佳答案
2023-11-16 14:53:43
  1. #include <stdio.h>

  2. double m_tax(double salary, int month) {
  3.     double tax = 0;
  4.     double annual_income = 0;

  5.     for (int i = 1; i <= month; i++) {
  6.         annual_income += salary;
  7.         if (annual_income <= 5000) {
  8.             continue;
  9.         } else if (annual_income <= 8000) {
  10.             tax += (annual_income - 5000) * 0.03;
  11.         } else if (annual_income <= 17000) {
  12.             tax += (annual_income - 8000) * 0.1 + 3000 * 0.03;
  13.         } else if (annual_income <= 30000) {
  14.             tax += (annual_income - 17000) * 0.2 + 9000 * 0.1 + 3000 * 0.03;
  15.         } else {
  16.             tax += (annual_income - 30000) * 0.25 + 13000 * 0.2 + 9000 * 0.1 + 3000 * 0.03;
  17.         }
  18.     }
  19.     return tax;
  20. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-11-16 14:53:43 | 显示全部楼层    本楼为最佳答案   
  1. #include <stdio.h>

  2. double m_tax(double salary, int month) {
  3.     double tax = 0;
  4.     double annual_income = 0;

  5.     for (int i = 1; i <= month; i++) {
  6.         annual_income += salary;
  7.         if (annual_income <= 5000) {
  8.             continue;
  9.         } else if (annual_income <= 8000) {
  10.             tax += (annual_income - 5000) * 0.03;
  11.         } else if (annual_income <= 17000) {
  12.             tax += (annual_income - 8000) * 0.1 + 3000 * 0.03;
  13.         } else if (annual_income <= 30000) {
  14.             tax += (annual_income - 17000) * 0.2 + 9000 * 0.1 + 3000 * 0.03;
  15.         } else {
  16.             tax += (annual_income - 30000) * 0.25 + 13000 * 0.2 + 9000 * 0.1 + 3000 * 0.03;
  17.         }
  18.     }
  19.     return tax;
  20. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-11-16 14:54:39 | 显示全部楼层
在C语言中,可以使用条件语句和循环结构来实现按月计算累计应纳税额的功能。以下是一个可能的解法:
  1. #include <stdio.h>
  2. double m_tax(double salary, int month) {
  3.     double tax = 0.0;
  4.     double totalSalary = 0.0; // 累计工资收入
  5.     double totalTaxableIncome = 0.0; // 累计应纳税所得额
  6.     for (int i = 1; i <= month; i++) {
  7.         totalSalary += salary; // 累计工资收入
  8.         if (totalSalary <= 5000) {
  9.             continue; // 小于等于5000元免税额,无需纳税
  10.         }
  11.         if (totalSalary <= 8000) {
  12.             totalTaxableIncome = totalSalary - 5000; // 累计应纳税所得额
  13.         } else if (totalSalary <= 17000) {
  14.             totalTaxableIncome = (totalSalary - 8000) * 0.9 + 3000;
  15.         } else if (totalSalary <= 30000) {
  16.             totalTaxableIncome = (totalSalary - 17000) * 0.8 + 9000;
  17.         } else if (totalSalary <= 40000) {
  18.             totalTaxableIncome = (totalSalary - 30000) * 0.75 + 13000;
  19.         } else if (totalSalary <= 60000) {
  20.             totalTaxableIncome = (totalSalary - 40000) * 0.7 + 17500;
  21.         } else if (totalSalary <= 85000) {
  22.             totalTaxableIncome = (totalSalary - 60000) * 0.65 + 23500;
  23.         } else {
  24.             totalTaxableIncome = (totalSalary - 85000) * 0.55 + 33500;
  25.         }
  26.     }
  27.     if (totalTaxableIncome > 0) {
  28.         // 根据累计应纳税所得额计算税额
  29.         if (totalTaxableIncome <= 3000) {
  30.             tax = totalTaxableIncome * 0.03;
  31.         } else if (totalTaxableIncome <= 12000) {
  32.             tax = totalTaxableIncome * 0.1 - 210;
  33.         } else if (totalTaxableIncome <= 25000) {
  34.             tax = totalTaxableIncome * 0.2 - 1410;
  35.         } else if (totalTaxableIncome <= 35000) {
  36.             tax = totalTaxableIncome * 0.25 - 2660;
  37.         } else if (totalTaxableIncome <= 55000) {
  38.             tax = totalTaxableIncome * 0.3 - 4410;
  39.         } else if (totalTaxableIncome <= 80000) {
  40.             tax = totalTaxableIncome * 0.35 - 7160;
  41.         } else {
  42.             tax = totalTaxableIncome * 0.45 - 15160;
  43.         }
  44.     }
  45.     return tax;
  46. }
  47. int main() {
  48.     double money, tax;
  49.     int i;
  50.     for (i = 1; i <= 12; i++) {
  51.         scanf("%lf", &money);
  52.         tax = m_tax(money, i);
  53.         printf("the sum of %d months tax is %.2f\n", i, tax);
  54.     }
  55.     return 0;
  56. }
复制代码

m_tax 函数中,首先定义了需要用到的变量:tax(税额),totalSalary(累计工资收入)和 totalTaxableIncome(累计应纳税所得额)。然后使用循环结构计算每个月的累计工资收入和累计应纳税所得额。

根据累计应纳税所得额,使用条件语句计算税额。最后,在 main 函数中,使用循环读入每个月的工资并调用 m_tax 函数计算并输出税额。

希望能对你有所帮助!如果还有其他问题,请随时提问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-21 05:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表