C语言实现 计算个人所得税务2种方法
[cpp]
1. #include <stdio.h>
2. #include <stdlib.h>
3. /*
4. 基于C语言的个人所得税计税系统
5.
6. 问题描述:
7. 我国现行的个人所得税计算方法如下:
8. 级数 全月应纳税所得额 税率(%)
9. 1 不超过500元的 5
10. 2 超过500元至2000元的部分 10
11. 3 超过2000元至5000元的部分 15
12. 4 超过5000元至20000元的部分 20
13. 5 超过20000元至40000元的部分 25
14. 6 超过40000元至60000元的部分 30
15. 7 超过60000元至80000元的部分 35
16. 8 超过80000元至100000元的部分 40
17. 9 超过100000元的部分 45
18. 本实验要求提示用户输入个人的收入后,给出纳税额度和税后工资。
19. */
20. void main()
21. {
22. float before_tax;
23. float after_tax;
24.
25. "Pleaafter_taxe input you after_taxalary:");//提示用户输入工资总额
26. "%f",&before_tax);//接收工资
27. "你的工资总额是: %7.2f",before_tax);
28.
29. after_tax = 0;
30. if (before_tax > 100000)
31. {
32. after_tax += (before_tax - 100000) * 0.45f;
33. before_tax = 100000;
34. }
35. if (before_tax > 80000)
36. {
37. after_tax += (before_tax - 80000) * 0.40f;
38. before_tax = 80000;
39. }
40. if (before_tax > 60000)
41. {
42. after_tax += (before_tax - 60000) * 0.35f;
43. before_tax = 60000;
44. }
45. if (before_tax > 40000)
46. {
47. after_tax += (before_tax - 40000) * 0.30f;
48. before_tax = 40000;
49. }
50. if (before_tax > 20000)
51. {
52. after_tax += (before_tax - 20000) * 0.25f;
53. before_tax = 20000;
54. }
55. if (before_tax > 5000)
56. {
57. after_tax += (before_tax - 5000) * 0.20f;
58. before_tax = 5000;
59. }
60. if (before_tax > 2000)
61. {
62. after_tax += (before_tax - 2000) * 0.15f;
63. before_tax = 2000;
64. }
65. if (before_tax > 500)
66. {
67. after_tax += (before_tax - 500) * 0.10f;
68. before_tax = 500;
69. }
70. if (before_tax > 0)
71. {
72. after_tax += (before_tax - 0) * 0.05f;
73. }
74.
75. "你的税额是: %7.2f",after_tax);
76. }
1)采用if 方法实现
自己写的:
#include <stdio.h>
#include <string.h>
#include <math.h>
static int single_tax(double income);
/*设置一个全局的变量*/
float tax;
int main(){
double income;
printf("Inpunt your income: \n");
scanf("%lf",&income);
single_tax(income);
return 0;
}
static int single_tax(double const income){ if(income > 0 && income <=23350){
tax = ((income) * 0.15); }
if(income >23350 && income <=56550)
{
tax = ((income - 23350)*0.28 )+ 3502.5; }
if(income >56660 && income <=117950)
{
tax = (income - 56660)*0.31 + 12798.50;
} if(income >117950 && income <=256500)
{
tax = (income - 117950)*0.36 + 31832; }
if(income >256500)
{
tax = (income - 256500)*0.396 + 81710;
}
printf("Your Tax is %7.2f \n",tax);
return 0;
}
2)借鉴Kenneth A.Reek 剧作<<C和指针>>
自己加入了一个main函数完成测试 。
代码如下:
/*打印个人所得税计算结果*/
#include <stdio.h>
#include <float.h>
static double income_limits[]={0,23350,56550,117950,256500,DBL_MAX};
static float base_tax[]={0,3502.5,12798.5,31832.5,81710.5};
static float percentage[]={.15,.28,.31,.36,.396};
double single_tax(double income);
int main()
{ double tax ;
double income;
printf("Input of Your Income :\n");
scanf("%lf",&income);
tax = single_tax(income);
printf("Your Tax is %7.2f :\n",tax);
}/*以下代码从书答案抄写过来*/
double
single_tax(double income)
{
/*定义一个标记、十分的简单与简洁。算法值得学习*/ int category;
for(category = 1;income >= income_limits[ category ];category +=1);
/* 指针提前了一个相对位置 */
category -= 1;
return base_tax[category] + percentage[category] * (income - income_limits[category]);}