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 | ...
随机推荐
- 【POJ】2236 Wireless Network
题目链接:http://poj.org/problem?id=2236 题意:给你n台计算机的坐标.d是可通信的最大距离.有两个操作. 1.O p 表示修复计算机p. 2.S p q表示询问pq是否能 ...
- DIV+CSS网页布局常用的一些基础知识
CSS命名规范 一.文件命名规范 全局样式:global.css:框架布局:layout.css:字体样式:font.css:链接样式:link.css:打印样式:print.css: 二.常用类/I ...
- vue cli3使用webpack4打包优化
去掉console.log,以及开启gzip const CompressionPlugin = require('compression-webpack-plugin');//引入gzip压缩插件 ...
- UC浏览器禁止图片阅读模式处理方法
本文转载自:https://www.cnblogs.com/MY0101/p/9969818.html UC浏览器点击图片会出现图片阅读模式. 如何处理? <img style=" w ...
- leetcode-219-存在重复元素②
题目描述: 第一次提交:超时 class Solution: def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool ...
- Windows taskkill
TASKKILL [/S system [/U username [/P [password]]]] { [/FI filter] [/PID processid | /IM imag ...
- SpringBoot生产/开发/测试多环境的选择
多环境选择 一般一套程序会被运行在多部不同的环境中,比如开发.测试.生产环境,每个环境的数据库地址,服务器端口这些都不经相同,若因为环境的变动而去改变配置的的参数,明显是不合理且易造成错误的 对于不同 ...
- CSS-基本语法/引用/文本设置/选择器/css3属性
CSS-基本语法/引用/文本设置 css基本语法及页面引用 css基本语法 css的定义方法是: 选择器 { 属性:值; 属性:值; 属性:值;} 选择器是将样式和页面元素关联起来的名称,属性是希望设 ...
- Iview+Vue CDN NetMvC 简单demo
1.引用相关js文件 2.菜单采用静态数据加载 3.效果展示 4.代码下载 https://github.com/sulin888/NetVueAdmin.git
- 纯CSS3实现图片展示特效
本文中要实现的一个纯CSS3的图片展示特效,以前只能用JavaScript实现,可想而知会受到多方面的限制,特别是性能.而今天我们将用简单的CSS3代码实现,你会发现它的动画效果在现代浏览器的帮助下无 ...