C语言实现 计算个人所得税务2种方法
- #include <stdio.h>
- #include <stdlib.h>
- /*
- 基于C语言的个人所得税计税系统
- 问题描述:
- 我国现行的个人所得税计算方法如下:
- 级数 全月应纳税所得额 税率(%)
- 1 不超过500元的 5
- 2 超过500元至2000元的部分 10
- 3 超过2000元至5000元的部分 15
- 4 超过5000元至20000元的部分 20
- 5 超过20000元至40000元的部分 25
- 6 超过40000元至60000元的部分 30
- 7 超过60000元至80000元的部分 35
- 8 超过80000元至100000元的部分 40
- 9 超过100000元的部分 45
- 本实验要求提示用户输入个人的收入后,给出纳税额度和税后工资。
- */
- void main()
- {
- float before_tax;
- float after_tax;
- printf("Pleaafter_taxe input you after_taxalary:");//提示用户输入工资总额
- scanf("%f",&before_tax);//接收工资
- printf("你的工资总额是: %7.2f",before_tax);
- after_tax = 0;
- if (before_tax > 100000)
- {
- after_tax += (before_tax - 100000) * 0.45f;
- before_tax = 100000;
- }
- if (before_tax > 80000)
- {
- after_tax += (before_tax - 80000) * 0.40f;
- before_tax = 80000;
- }
- if (before_tax > 60000)
- {
- after_tax += (before_tax - 60000) * 0.35f;
- before_tax = 60000;
- }
- if (before_tax > 40000)
- {
- after_tax += (before_tax - 40000) * 0.30f;
- before_tax = 40000;
- }
- if (before_tax > 20000)
- {
- after_tax += (before_tax - 20000) * 0.25f;
- before_tax = 20000;
- }
- if (before_tax > 5000)
- {
- after_tax += (before_tax - 5000) * 0.20f;
- before_tax = 5000;
- }
- if (before_tax > 2000)
- {
- after_tax += (before_tax - 2000) * 0.15f;
- before_tax = 2000;
- }
- if (before_tax > 500)
- {
- after_tax += (before_tax - 500) * 0.10f;
- before_tax = 500;
- }
- if (before_tax > 0)
- {
- after_tax += (before_tax - 0) * 0.05f;
- }
- printf("你的税额是: %7.2f",after_tax);
- }
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种方法的更多相关文章
- R语言中样本平衡的几种方法
R语言中样本平衡的几种方法 在对不平衡的分类数据集进行建模时,机器学习算法可能并不稳定,其预测结果甚至可能是有偏的,而预测精度此时也变得带有误导性.在不平衡的数据中,任一算法都没法从样本量少的类中获取 ...
- C语言清空输入缓冲区的N种方法对比
转自C语言清空输入缓冲区的N种方法对比 C语言中有几个基本输入函数: //获取字符系列 int fgetc(FILE *stream); int getc(FILE *stream); int get ...
- 用Python计算幂的两种方法,非递归和递归法
用Python计算幂的两种方法: #coding:utf-8 #计算幂的两种方法.py #1.常规方法利用函数 #不使用递归计算幂的方法 """ def power(x, ...
- C语言数据结构-创建链表的四种方法
结点类型: typedef int datatype; typedef struct NODE{ datatype data; struct NODE *next; }Node,*LinkList; ...
- C语言结构体定义的几种方法
什么是结构体? 在C语言中,结构体(struct)指的是一种数据结构,是C语言中聚合数据类型(aggregate data type)的一类.结构体可以被声明为变量.指针或数组等,用以实现较复杂的数据 ...
- MySQL根据出生日期计算年龄的五种方法比较
方法一 SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age 方法一,作者也说出了缺陷,就是当日 ...
- C语言结构体初始化的四种方法(转载)
原文:https://blog.csdn.net/ericbar/article/details/79567108 定义 struct InitMember { int first: double s ...
- C语言提高代码效率的几种方法
一段完美的代码不仅在于找到一个给定的问题的解决方案,但在它的简单性,有效性,紧凑性和效率(内存).设计的代码比实际执行更难.因此,每一个程序员当用C语言开发时,都应该保持这些基本的东西在头脑中.本文向 ...
- C语言播放声音最简单的两种方法
1. 假设仅须要播放波形文件wav格式的声音,非常easy.仅仅需一句话: PlaySound(TEXT("Data\\1.wav"), NULL, SND_FILENAME | ...
随机推荐
- 快速创建vuepress项目(使用vuepress写文档)
vuepress的官方文档:https://vuepress.vuejs.org/zh/guide/ 参考:https://segmentfault.com/a/1190000016333850 ht ...
- FaceNet pre-trained模型以及FaceNet源码使用方法和讲解
Pre-trained models Model name LFW accuracy Training dataset Architecture 20180408-102900 0.9905 CASI ...
- leetcood学习笔记-53*-最大子列和
题目描述: 方法一:O(N) class Solution(object): def maxSubArray(self, nums): sum = 0 max_sub_sum = nums[0] fo ...
- Windows netstat
{ 显示协议统计信息和当前 TCP/IP 网络连接. NETSTAT [-a] [-b] [-e] [-f] [-n] [-o] [-p proto] [-r] [-s] [-x] [-t] [int ...
- poj2954Triangle
传送门 Pick定理 定点坐标为整点的三角形,面积为S,边上的整点个数为L,三角形内部整点个数为N S=N+L/2-1 //Achen #include<algorithm> #inclu ...
- 机器学习 101 Mahout 简介 建立一个推荐引擎 使用 Mahout 实现集群 使用 Mahout 实现内容分类 结束语 下载资源
机器学习 101 Mahout 简介 建立一个推荐引擎 使用 Mahout 实现集群 使用 Mahout 实现内容分类 结束语 下载资源 相关主题 在信息时代,公司和个人的成功越来越依赖于迅速 ...
- 阿里云CentOs7上安装GitLab
一.安装 基本上可以根据官网的教程来安装:https://www.gitlab.com.cn/installation/#centos-7 只不过我们暂时没有邮件服务器,所以postfix没有安装. ...
- selector是在文件夹drawable中进行定义的xml文件转载 https://www.cnblogs.com/fx2008/p/3157040.html
获取Drawable对象: Resources res = mContext.getResources(); Drawable myImage = res.getDrawable(R.drawable ...
- ELK5.2+kafka+zookeeper+filebeat集群部署
架构图 考虑到日志系统的可扩展性以及目前的资源(部分功能复用),整个ELK架构如下: 架构解读 : (整个架构从左到右,总共分为5层) 第一层.数据采集层 最左边的是业务服务器集群,上面安装了file ...
- Single Thread Execution 能通过这座桥的只有一个人
直奔主题, Single Thread Execution也称作Critical Section(临界区),范例如下: public class SingleThreadGate { public s ...