qzyx
本题目要求读入每月工资,计算按月需要累计缴纳的税额(税率见下图),此处只需显示应缴纳的税额,无需减去已缴纳部分。结果保留两位小数。 注意:每月有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语言怎么做 #include <stdio.h>
double m_tax(double salary, int month) {
double tax = 0;
double annual_income = 0;
for (int i = 1; i <= month; i++) {
annual_income += salary;
if (annual_income <= 5000) {
continue;
} else if (annual_income <= 8000) {
tax += (annual_income - 5000) * 0.03;
} else if (annual_income <= 17000) {
tax += (annual_income - 8000) * 0.1 + 3000 * 0.03;
} else if (annual_income <= 30000) {
tax += (annual_income - 17000) * 0.2 + 9000 * 0.1 + 3000 * 0.03;
} else {
tax += (annual_income - 30000) * 0.25 + 13000 * 0.2 + 9000 * 0.1 + 3000 * 0.03;
}
}
return tax;
}
在C语言中,可以使用条件语句和循环结构来实现按月计算累计应纳税额的功能。以下是一个可能的解法:
#include <stdio.h>
double m_tax(double salary, int month) {
double tax = 0.0;
double totalSalary = 0.0; // 累计工资收入
double totalTaxableIncome = 0.0; // 累计应纳税所得额
for (int i = 1; i <= month; i++) {
totalSalary += salary; // 累计工资收入
if (totalSalary <= 5000) {
continue; // 小于等于5000元免税额,无需纳税
}
if (totalSalary <= 8000) {
totalTaxableIncome = totalSalary - 5000; // 累计应纳税所得额
} else if (totalSalary <= 17000) {
totalTaxableIncome = (totalSalary - 8000) * 0.9 + 3000;
} else if (totalSalary <= 30000) {
totalTaxableIncome = (totalSalary - 17000) * 0.8 + 9000;
} else if (totalSalary <= 40000) {
totalTaxableIncome = (totalSalary - 30000) * 0.75 + 13000;
} else if (totalSalary <= 60000) {
totalTaxableIncome = (totalSalary - 40000) * 0.7 + 17500;
} else if (totalSalary <= 85000) {
totalTaxableIncome = (totalSalary - 60000) * 0.65 + 23500;
} else {
totalTaxableIncome = (totalSalary - 85000) * 0.55 + 33500;
}
}
if (totalTaxableIncome > 0) {
// 根据累计应纳税所得额计算税额
if (totalTaxableIncome <= 3000) {
tax = totalTaxableIncome * 0.03;
} else if (totalTaxableIncome <= 12000) {
tax = totalTaxableIncome * 0.1 - 210;
} else if (totalTaxableIncome <= 25000) {
tax = totalTaxableIncome * 0.2 - 1410;
} else if (totalTaxableIncome <= 35000) {
tax = totalTaxableIncome * 0.25 - 2660;
} else if (totalTaxableIncome <= 55000) {
tax = totalTaxableIncome * 0.3 - 4410;
} else if (totalTaxableIncome <= 80000) {
tax = totalTaxableIncome * 0.35 - 7160;
} else {
tax = totalTaxableIncome * 0.45 - 15160;
}
}
return tax;
}
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;
}
在 m_tax 函数中,首先定义了需要用到的变量:tax(税额),totalSalary(累计工资收入)和 totalTaxableIncome(累计应纳税所得额)。然后使用循环结构计算每个月的累计工资收入和累计应纳税所得额。
根据累计应纳税所得额,使用条件语句计算税额。最后,在 main 函数中,使用循环读入每个月的工资并调用 m_tax 函数计算并输出税额。
希望能对你有所帮助!如果还有其他问题,请随时提问。
页:
[1]