在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 函数计算并输出税额。
希望能对你有所帮助!如果还有其他问题,请随时提问。 |