1. #include <stdio.h>
  2. #include <stdlib.h>
  3. /*
  4. 基于C语言的个人所得税计税系统
  5. 问题描述:
  6. 我国现行的个人所得税计算方法如下:
  7.  级数 全月应纳税所得额     税率(%)
  8.   1 不超过500元的           5
  9.   2 超过500元至2000元的部分     10
  10.   3 超过2000元至5000元的部分     15
  11.   4 超过5000元至20000元的部分    20
  12.   5 超过20000元至40000元的部分    25
  13.   6 超过40000元至60000元的部分    30
  14.   7 超过60000元至80000元的部分    35
  15.   8 超过80000元至100000元的部分   40
  16.   9 超过100000元的部分         45
  17. 本实验要求提示用户输入个人的收入后,给出纳税额度和税后工资。
  18. */
  19. void main()
  20. {
  21. float before_tax;
  22. float after_tax;
  23. printf("Pleaafter_taxe input you after_taxalary:");//提示用户输入工资总额
  24. scanf("%f",&before_tax);//接收工资
  25. printf("你的工资总额是: %7.2f",before_tax);
  26. after_tax = 0;
  27. if (before_tax > 100000)
  28. {
  29. after_tax += (before_tax - 100000) * 0.45f;
  30. before_tax = 100000;
  31. }
  32. if (before_tax > 80000)
  33. {
  34. after_tax += (before_tax - 80000) * 0.40f;
  35. before_tax = 80000;
  36. }
  37. if (before_tax > 60000)
  38. {
  39. after_tax += (before_tax - 60000) * 0.35f;
  40. before_tax = 60000;
  41. }
  42. if (before_tax > 40000)
  43. {
  44. after_tax += (before_tax - 40000) * 0.30f;
  45. before_tax = 40000;
  46. }
  47. if (before_tax > 20000)
  48. {
  49. after_tax += (before_tax - 20000) * 0.25f;
  50. before_tax = 20000;
  51. }
  52. if (before_tax > 5000)
  53. {
  54. after_tax += (before_tax - 5000) * 0.20f;
  55. before_tax = 5000;
  56. }
  57. if (before_tax > 2000)
  58. {
  59. after_tax += (before_tax - 2000) * 0.15f;
  60. before_tax = 2000;
  61. }
  62. if (before_tax > 500)
  63. {
  64. after_tax += (before_tax - 500) * 0.10f;
  65. before_tax = 500;
  66. }
  67. if (before_tax > 0)
  68. {
  69. after_tax += (before_tax - 0) * 0.05f;
  70. }
  71. printf("你的税额是: %7.2f",after_tax);
  72. }

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]);

}

C语言实现 计算个人所得税务2种方法的更多相关文章

  1. R语言中样本平衡的几种方法

    R语言中样本平衡的几种方法 在对不平衡的分类数据集进行建模时,机器学习算法可能并不稳定,其预测结果甚至可能是有偏的,而预测精度此时也变得带有误导性.在不平衡的数据中,任一算法都没法从样本量少的类中获取 ...

  2. C语言清空输入缓冲区的N种方法对比

    转自C语言清空输入缓冲区的N种方法对比 C语言中有几个基本输入函数: //获取字符系列 int fgetc(FILE *stream); int getc(FILE *stream); int get ...

  3. 用Python计算幂的两种方法,非递归和递归法

    用Python计算幂的两种方法: #coding:utf-8 #计算幂的两种方法.py #1.常规方法利用函数 #不使用递归计算幂的方法 """ def power(x, ...

  4. C语言数据结构-创建链表的四种方法

    结点类型: typedef int datatype; typedef struct NODE{ datatype data; struct NODE *next; }Node,*LinkList; ...

  5. C语言结构体定义的几种方法

    什么是结构体? 在C语言中,结构体(struct)指的是一种数据结构,是C语言中聚合数据类型(aggregate data type)的一类.结构体可以被声明为变量.指针或数组等,用以实现较复杂的数据 ...

  6. MySQL根据出生日期计算年龄的五种方法比较

    方法一 SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age 方法一,作者也说出了缺陷,就是当日 ...

  7. C语言结构体初始化的四种方法(转载)

    原文:https://blog.csdn.net/ericbar/article/details/79567108 定义 struct InitMember { int first: double s ...

  8. C语言提高代码效率的几种方法

    一段完美的代码不仅在于找到一个给定的问题的解决方案,但在它的简单性,有效性,紧凑性和效率(内存).设计的代码比实际执行更难.因此,每一个程序员当用C语言开发时,都应该保持这些基本的东西在头脑中.本文向 ...

  9. C语言播放声音最简单的两种方法

    1. 假设仅须要播放波形文件wav格式的声音,非常easy.仅仅需一句话: PlaySound(TEXT("Data\\1.wav"), NULL, SND_FILENAME | ...

随机推荐

  1. 快速创建vuepress项目(使用vuepress写文档)

    vuepress的官方文档:https://vuepress.vuejs.org/zh/guide/ 参考:https://segmentfault.com/a/1190000016333850 ht ...

  2. FaceNet pre-trained模型以及FaceNet源码使用方法和讲解

    Pre-trained models Model name LFW accuracy Training dataset Architecture 20180408-102900 0.9905 CASI ...

  3. leetcood学习笔记-53*-最大子列和

    题目描述: 方法一:O(N) class Solution(object): def maxSubArray(self, nums): sum = 0 max_sub_sum = nums[0] fo ...

  4. Windows netstat

    { 显示协议统计信息和当前 TCP/IP 网络连接. NETSTAT [-a] [-b] [-e] [-f] [-n] [-o] [-p proto] [-r] [-s] [-x] [-t] [int ...

  5. poj2954Triangle

    传送门 Pick定理 定点坐标为整点的三角形,面积为S,边上的整点个数为L,三角形内部整点个数为N S=N+L/2-1 //Achen #include<algorithm> #inclu ...

  6. 机器学习 101 Mahout 简介 建立一个推荐引擎 使用 Mahout 实现集群 使用 Mahout 实现内容分类 结束语 下载资源

      机器学习 101 Mahout 简介 建立一个推荐引擎 使用 Mahout 实现集群 使用 Mahout 实现内容分类 结束语 下载资源 相关主题   在信息时代,公司和个人的成功越来越依赖于迅速 ...

  7. 阿里云CentOs7上安装GitLab

    一.安装 基本上可以根据官网的教程来安装:https://www.gitlab.com.cn/installation/#centos-7 只不过我们暂时没有邮件服务器,所以postfix没有安装. ...

  8. selector是在文件夹drawable中进行定义的xml文件转载 https://www.cnblogs.com/fx2008/p/3157040.html

    获取Drawable对象: Resources res = mContext.getResources(); Drawable myImage = res.getDrawable(R.drawable ...

  9. ELK5.2+kafka+zookeeper+filebeat集群部署

    架构图 考虑到日志系统的可扩展性以及目前的资源(部分功能复用),整个ELK架构如下: 架构解读 : (整个架构从左到右,总共分为5层) 第一层.数据采集层 最左边的是业务服务器集群,上面安装了file ...

  10. Single Thread Execution 能通过这座桥的只有一个人

    直奔主题, Single Thread Execution也称作Critical Section(临界区),范例如下: public class SingleThreadGate { public s ...