内容正文:
第4章
选择结构程序设计
王小姐9月份的业绩不错,根据合同,公司给她薪资为58000
元,中华人民共和国个人所得税法规定:从2011年9月1日起,
中国内地个税免征额调至3500元。当月的收入超过3500元按照
以下表格提供的利率缴纳个人收入所得税,王小姐非常想知道
她9月拿到自己手里的钱是多少?
级数
全月应纳税所得额(含税级距)
税率(%
1
全月应纳税所得额不超过1500元
3%
2
全月应纳税所得额超过1500元至4500元
10%
3
全月应纳税所得额超过4500元至9000元
20%
4
全月应纳税所得额超过9000元至35000元
25%
5
全月应纳税所得额超过35000元至55000元
30%
6
全月应纳税所得额超过55000元至80000元
35%
7
全月应纳税所得额超过80000元
45%
●
选择结构的作用是根据给定的条件来决定做什么的操作。
●f语句
f-else语句
●i
●if-else if-else语句
if-else语句
f(表达式)
表达式
语句1
语句2
语句1
else
语句2
int a.b,max;
【例1】利用if-else语句
scanf("%d,%d",&a,&b);
求两个整数中较大者。
if (a>b)
{max=a;
else
(max=b;}
if-else语句
【例2】求三个整数a,b,c中的最大数。
单f语句
int a,b,c,max;
scanf("%d,%d,%d ",&a,&b,&c);
其一般形式为:
if (a>b)
f(表达式)
{max=a;}
语句
else
{max=b;}
if (max c)
{max=c;}
单f语句
【例3】利用单f语句
表达1
语句
求两个整数中较大者。
int a.b.max;
scanf("%d,%d",&a,&b);
max=a;
if(max<b)
[max=b;}
f-else if-else语句
表达式1
假
真
表达式2
假
真
表达式3
假
真
表达式m-1
假
真
语可1
图百2
语可3
语百血1
语
系统首先求解表达式1的值,当其值为真”(非0)时,执行语句1,然后跳出
该选择结构:否则求解表达式2的值,当其值为真”(非0)时,则执行语句2,
然后跳出该选择结构:否则再继续求解表达式3,当其值为“真”(非0)时,
执行语句3,然后跳出该选择结构:否则接着进行判断,依次类推。如果经过
求解,所有的表达式都为假”(0),就执行最后一个ls部分的语句m,从而
结束整个if语句。
给出百分制的成绩,要求输出成绩等级A、B、C、D、E。90分以上
为A,80~89分为B,70~79分为C,60~69分为D,60分以下为E.
设成绩为score,
假设取值在0~100之间,没有错误的输入,则有:
0<score<60
E
int score;
60 <scores≤69
D
scanf("%d",&score);
70 <score:≤79
C
80 <scores≤89
B
if(score>=0&&score<60)
90 <scorez≤100
A
{printf("grade is Eln");}
else if(score>=60&&score<=69)
printf("grade is DIn");
else if(score>=70&&score<=79)
printf("grade is Cln");}
else if(score>=80&&score<=89)
{printf("grade is B
");}
else
(printf("grade is Aln");
#include "stdio.h"
void main()
int score;
#include "stdio.h"
#include "stdio.h"
I void main()
void main()
int score;
int score;
scanf("%d",&score)方
scanf("y6d",&score)方
if(score>=0 &score<60)
if(score>=0&&score<60)
printf("grade is En"),
printf("grade is En");
else if(score<=79)
else if(score>=60&&score<=69)
printf("grade is Cn");
printf("grade is Dn"),
else if(score<=89)
else if(score>=70&&score<=79)
printf("grade is Bin")
printf"grade is C
")方
else if(score<=6