【C语言】目标题:计算个人所得税
作者:野牛程序员:2023-10-20 08:49:01C语言阅读 2730
【C语言】目标题 计算个人所得税 输入一个职工的月薪salary,输出应交的个人所得税tax(保留2位小数)。
题目要求:
tax = rate * (salary-850)/100
当 salary <=850 时,rate=0;
当 850 < salary<= 1350 时,rate=5;
当 1350<salary<=2850时,rate =10;
当 2850< salary<=5850时,rate =15; 当 5850< salary 时,rate=20;
【样例输入】1010.87
【输出】 tax=8.04
下面是C语言代码
#include <stdio.h> int main() { float salary, rate, tax; scanf("%f", &salary); if (salary <= 850) { rate = 0; } else if (salary <= 1350) { rate = 5; } else if (salary <= 2850) { rate = 10; } else if (salary <= 5850) { rate = 15; } else { rate = 20; } tax = rate * (salary - 850) / 100; printf("tax=%.2f\\n", tax); return 0; }
下面是C++代码:
#include <iostream> #include <iomanip> using namespace std; int main() { float salary, rate, tax; cin >> salary; if (salary <= 850) { rate = 0; } else if (salary <= 1350) { rate = 5; } else if (salary <= 2850) { rate = 10; } else if (salary <= 5850) { rate = 15; } else { rate = 20; } tax = rate * (salary - 850) / 100; cout << "tax=" << std::fixed << setprecision(2) << tax << endl; return 0; }
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892