|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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语言怎么做
- #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;
- }
复制代码
|
|