预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共56页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

第四章判定、分支和循环/*absolutevalue*/ #include<stdio.h> main() {intx,y; printf("Enteraninteger:"); scanf("%d",&x); y=x; if(y<0) y=-y; printf("\ninteger:%d-->absolutevalue:%d\n",x,y); }引入复合语句:用{…}括起来的一组语句 一般形式:{[数据说明部分;] 执行语句部分; } expr例if(x>y)max=x; elsemax=y;应用扩展例百分制成绩转换为五级制p122 80to100Honours 60to79FirstDivision 50to59SecondDivision 40to49ThirdDivision 0to39Fail 例累进电费p124例根据税前收入计算税后收入/*chartype*/ #include<stdio.h> main() {charc; printf("Enteracharacter:"); c=getchar(); if(c<0x20)printf("Thecharacterisacontrolcharacter\n"); elseif(c>='0'&&c<='9')printf("Thecharacterisadigit\n"); elseif(c>='A'&&c<='Z')printf("Thecharacterisacapitalletter\n"); elseif(c>='a'&&c<='z')printf("Thecharacterisalowerletter\n"); elseprintf("Thecharacterisothercharacter\n"); } 例:if(a==b) if(b==c) printf(“a==b==c”); else printf(“a!=b”);/*SelectLabel*/ #include<stdio.h> main() {intc; printf("Entermornorhorother:"); c=getchar(); switch(c) {case'm':printf("\nGoodmorning!\n");break; case'n':printf("\nGoodnight!\n");break; case'h':printf("\nHello!\n");break; default:printf("\n????????\n");break; } }switch(表达式) {caseE1: 语句组1; break; caseE2: 语句组2; break; ……. caseEn: 语句组n; break; [default: 语句组; break;] }例百分制成绩转换为五级制p122 80to100Honours 60to79FirstDivision 50to59SecondDivision 40to49ThirdDivision 0to39Fail 用SwitchStatement.例用if和goto语句构成循环,求1+2+…+100例从键盘输入一组数据,以0结束输入,求数据和例pp135RANGEofNumbers: Asurveyofthecomputermacketshowthatpersonalcomputersaresoldatvaryingcosts bythevendors.Thefollowingisthelistofcosts(inhundreds)quotedbysomevendors: 35.00,40.50,25.00,31.25,68.15, 47.00,26.65,29.00,53.45,62.50 Determinetheaveragecostandtherangeofvalues.例pp136Pay-BillCalculations: Amanufacturingcompanyhasclassifieditsexecutivesintofourlevelsforthebenefitofcertainperks.Thelevelsandcorrespondingperksareshownbelow: Perks Level------------------------------------------------------------------ ConveyanceEntertainment allowanceallowance 11000500 2750200 3500100 4250---- Anexecutive’sgrosssalaryincludesbasicpay,houserentallowanceat25%