运算符
+ - * / % == != !(取反) ++ -- > < >= <=
int a = 10;
int b = 20;
结果不需要存储
printf("a + b = %d\n", a + b);
需要存储结果
int c = a + b;
printf("a + b = %d\n", c);
除: / 取整数部分 10/3 = 3
% 取余数部分 10%4 = 1
a++ 自增 a = a + 1
a-- 自减 a = a - 1
a++ 当表达式执行完毕之后再对当前变量+1
int score = 80;
printf("score is %d\n", score++);//80
=
printf("score is %d\n", score);//80
score ++;
++a 立刻改变
printf("score is %d %d\n", score++,score);//80 81
printf("score is %d\n", score);//81
int weight = 120;
printf("my weight is %d %d\n", ++weight,weight);//121 121
printf("my weight is %d\n", weight);//121
if条件判断语句
if (条件){}
布尔类型 真(成立 非零即真 true)
假(不成立 0 false)
if (-1){
printf("ok\n");
}
if (false){
printf("是真\n");
}
int password = 123;
= 赋值
== 比较是否相同
if (password == 123){
printf("密码正确\n");
}
! 取反
bool result = false;
if (!result){
printf("条件成立\n");
}
当对数据进行取反操作时 会将这个变量或者数据当做bool值来对待
int i = 0;
int j = !i; // true 1
保存税前薪资
float salary = 0;
养老保险
float endowmentInsurance = 0;
医疗保险
float medicalInsurance = 0;
记录个人所得税
float tax = 0;
提示用户操作
printf("请输入税前薪资:");
接收用户的输入
scanf("%f", &salary);
确定养老保险
endowmentInsurance = salary * 0.08;
确定医疗保险
medicalInsurance = salary * 0.02;
确定个人所得税
if (salary >= 5000 && salary < 36000){
tax = (salary-5000)*0.03;
}
if (salary >= 36000 && salary < 144000){
tax = (36000-5000)*0.03 + (salary-36000)*0.1;
}
输出结果
printf("税后收入:%f\n",
salary - tax - medicalInsurance - endowmentInsurance);
printf("个人所得税:%f\n", tax);
printf("养老保险:%f\n", endowmentInsurance);
printf("医疗保险:%f\n", medicalInsurance);