用c语言编写:个人所得税,应纳税款的计算公式如下: x |+2 - sin (x2) 收入收入<1000元部分 1000元<=收入<2000元的部分 2000元<=收入<4000元的部分 4000元<=收入<6000元的部分收入>=6000元的部分 税率 0% 5% 10% 15% 20% 输入某人的收入,计算出应纳税额及实际得到的报酬。(使用 if 和 switch 两种方法)
时间: 2023-06-25 22:02:40 浏览: 83
使用 if 语句的代码:
```c
#include <stdio.h>
#include <math.h>
int main()
{
double income, tax, net_income;
printf("请输入您的收入:");
scanf("%lf", &income);
if (income < 1000) {
tax = 0;
}
else if (income < 2000) {
tax = (income - 1000) * 0.05;
}
else if (income < 4000) {
tax = 50 + (income - 2000) * 0.1;
}
else if (income < 6000) {
tax = 250 + (income - 4000) * 0.15;
}
else {
tax = 550 + (income - 6000) * 0.2;
}
net_income = income - tax;
printf("您应缴纳的税额为:%lf\n", tax);
printf("您实际得到的报酬为:%lf\n", net_income);
return 0;
}
```
使用 switch 语句的代码:
```c
#include <stdio.h>
#include <math.h>
int main()
{
double income, tax, net_income;
printf("请输入您的收入:");
scanf("%lf", &income);
switch ((int)floor(income / 1000)) {
case 0:
tax = 0;
break;
case 1:
tax = (income - 1000) * 0.05;
break;
case 2:
tax = 50 + (income - 2000) * 0.1;
break;
case 3:
tax = 250 + (income - 4000) * 0.15;
break;
default:
tax = 550 + (income - 6000) * 0.2;
break;
}
net_income = income - tax;
printf("您应缴纳的税额为:%lf\n", tax);
printf("您实际得到的报酬为:%lf\n", net_income);
return 0;
}
```