if语句练习题学习资料
c语言(if语句)练习题

一、程序填空:输入3个数分别是a 、b 、c 。
先将a 、b 中的较大致存入a 中、较小数存入b 中;再让a 与c 比较,将a 与c 中的较大数存在a 中,较小数存人c 中;最后比较b 与c ,将b 、c 中的较大数存入b 中,较小数存入c 中。
这样a 、b 、c 这3个数的序列即按从大到小排列。
#include <stdio.h>main(){int a,b,c,t;printf(“Input three integers:”);scanf(“%d,%d,%d ”, ); /*输入a ,b ,c3个整数*/if(a<b)/*交换a ,b 的值*/if(a<c)/*交换a ,c 的值*/if(b<c)/*交换b ,c 的值*/printf(“Big to small is:%d,%d,%d ”,a,b,c);}二、程序改错:下面的程序实现求解()()()2222100100x x f x x x ⎧->⎪=⎨--≤⎪⎩分析下列程序代码能否实现,如果程序中存在错误,请修改程序中的错误,然后运行修改后的程序。
#include <stdio.h>main(){int x,y;scanf(“%d ”,&x);if(x*x – 10>0);y = x*x;printf(“y= %d\n ”,y);elsey=-(x*x);printf(“y=%d\n ”,y);}三、编程题1、编写程序从键盘上输入两个整数,检查第一个数是否能被第二个数整除。
2、编写一个程序,输入某人的身高(cm)和体重(kg),按下式确定其体重是否为标准、过胖或过瘦。
(1)标准体重=身高-110;(2)超过标准体重5kg(即大于5kg)为过胖;(3)低于标准体重5kg(即小于5kg)为过瘦。
3、判断某一年是否是闰年:(1) 被4整除但不能被100整除; 或(2) 被400整除;4、编写程序计算升高:每个做父母的都关心自己孩子成人后的身高,据有关生理卫生知识与数理统计分析表明,影响小孩成人后身高的因素有遗传、饮食习惯与坚持体育锻炼等。
if条件句练习题及答案

if条件句练习题及答案一、选择题1. 如果明天不下雨,我们将去野餐。
A) If it doesn't rain tomorrow, we will go for a picnic.B) If it rains tomorrow, we will go for a picnic.C) If it will rain tomorrow, we will go for a picnic.D) If it rains tomorrow, we will not go for a picnic.2. 只有当我完成作业后,我才会看电视。
A) I will watch TV only after I finish my homework.B) I will watch TV only before I finish my homework.C) I will watch TV only while I finish my homework.D) I will not watch TV only after I finish my homework.3. 除非他道歉,否则我不会原谅他。
A) I will forgive him unless he apologizes.B) I will not forgive him unless he apologizes.C) I will forgive him if he does not apologize.D) I will not forgive him if he apologizes.4. 只要我们努力工作,我们就能成功。
A) We can succeed as long as we work hard.B) We can succeed unless we work hard.C) We can succeed if we do not work hard.D) We cannot succeed unless we work hard.5. 如果你饿了,冰箱里有食物。
(完整版)if条件状语从句练习与答案

(完整版)if条件状语从句练习与答案if_条件状语从句的时态练习及答案_初中习题集I.单项选择1.If you to the party, you’ll have a great time.a.will gob. wentc. god. going2.It will be a long time peter his work.a.since, has finishedb. after, finishesc. when, will finishd. before, finishes.3.what will father us from Japan?a.takeb. bringc. carryd. make4.Weifang is famous kitesa.forb. toc. ond. with5.I her the answer if she me.a. can tell, will askb. will tell, will askc. would tell, askd. will tell, asks6.– what are you going to do tomorrow?--we’ll go to the library tomorrow if it .a.isn’t rainb. rainc. won’t raind. doesn’t rain 7.—Do you know when he will come back tomorrow?--sorry, I don’t know. when he back, I’ll tell you.a. comesb. will comec. comed. may come8.what will you do if you to the old folk’s home visit?a.gob. wentc. goingd. will go9.If I eat food, I’ll be very fat.a.too manyb. many tooc. too muchd. much too10.I’ll give the book to him if he here next sunday.a. will comeb. comesc. is comingd. came11. There an english film in our school tomorrow.a. is going to haveb. will havec. is going to bed. has12.Could you tell us where ?a.will the next olympic games heldb.the next olympic games will be heldc.would the next olympic games be heldd.the next olympic games would be held13.When my mother returned last night,I a book.a. readb. am readingc. was readingd. am going to read14.What you when it began to rain?a. do, dob. were, doingc. are, doingd. did, do15.I’ll wake you up when he back.a. willb. is going to comec. comesd. comeII、用所给词的适当形式填空1.If you (feel) tired, you (have) to have a rest.2.Where he (see) the film if he (have) time?3.If there (be) fewer trees, there (be) more pollution.4.He (dress) more casually if he (not work) on weekends.5.If marcia (live) alone, she (keep) a pet parrot./doc/d011234800.html,na (buy) a new dress if the old one (be) out of style.7.The twins (fight) if they (argue).8.I (have) a bake sale if I (need) money for education.9.Peter (send) me a beautiful souvenir if he (tour) spain.10.I f mr. green (say) I am hard- working, my parents (feel) glad.11.I (go) to the beach if it (not rain) this week.12.they (have) a match if the p.e. teacher (be) busy?13.He (write) a letter to his grandparents if he (get) his report card this week.14.If she (get) up late, she (not catch) the early bus.15.Peter (major) in English if he (pass) the exams in peking university.III. 完成句子1.如果他到的晚了会发生什么事情?What if he late?2.如果努力学习,你就会取得好成绩。
if判断练习题

if判断练习题题目:if判断练习题正文:if判断是在编程中常用的一种控制结构,用于根据条件的真假来执行不同的代码块。
if判断练习题可以帮助我们巩固对if判断语句的理解和运用。
下面是一些if判断练习题,供大家练习和思考。
练习一:请编写一个程序,判断一个整数是否为正数。
如果是正数,则输出"是正数";如果是负数,输出"是负数";如果是0,则输出"是零"。
解答一:```pythonnum = int(input("请输入一个整数:"))if num > 0:print("是正数")elif num < 0:print("是负数")else:print("是零")```练习二:请编写一个程序,判断一个年份是否为闰年。
如果是闰年,则输出"是闰年";如果不是闰年,则输出"不是闰年"。
解答二:```pythonyear = int(input("请输入一个年份:"))if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):print("是闰年")else:print("不是闰年")```练习三:请编写一个程序,判断一个输入的字符串是否为回文字符串。
回文字符串是指正读和倒读都相同的字符串。
如果是回文字符串,则输出"是回文字符串";否则输出"不是回文字符串"。
解答三:```pythontext = input("请输入一个字符串:")if text == text[::-1]:print("是回文字符串")else:print("不是回文字符串")```练习四:请编写一个程序,判断一个年龄是否为成年人。
c语言if语句习题,C语言练习

c语⾔if语句习题,C语⾔练习C语⾔练习D.算法只能被有限的⽤户使⽤18、 有如下嵌套的if语句:以下选项中与上述if语句等价的语句是( )。
A. k=(aB.B.:((b>C.?b:C.;B.k=(aD.k=(a19、 有以下程序:程序运⾏后的输出结果是( )。
A.0B.1C.2D.320、 有三个关系R、S和T如下:由关系R和S通过运算得到关系T,则所使⽤的运算为( )。
A.笛卡尔积B.交C.并D.⾃然连接21、 有以下程序(说明:字母A的ASCIl码值是65):程序运⾏后的输出结果是( )。
A.BTB.YEC.YTD.BY22、 下列叙述中正确的是( )。
A.顺序存储结构的存储⼀定是连续的,链式存储结构的存储空间不⼀定是连续的B.顺序存储结构只针对线性结构,链式存储结构只针对⾮线性结构C.顺序存储结构能存储有序表,链式存储结构不能存储有序表D.链式存储结构⽐顺序存储结构节省存储空间23、 软件测试的⽬的是( )。
A.评估软件可靠性B.发现并改正程序中的错误C.改正程序中的错误D.发现程序中的错误24、 软件⽣命周期是指( )。
A.软件产品从提出、实现、使⽤维护到停⽌使⽤退役的过程B.软件从需求分析、设计、实现到测试完成的过程C.软件的开发过程D.软件的运⾏维护过程25、 以下关于retllm语句的叙述中正确的是( )。
A.⼀个⾃定义函数中必须有⼀条return语句B.⼀个⾃定义函数中可以根据不同情况设置多条retum语句C.定义成void类型的函数中可以有带返回值的return语句D.没有return语句的⾃定义函数在执⾏结束时不能返回到调⽤处26、 在长度为n的有序线性表中进⾏⼆分查找,最坏情况下需要⽐较的次数是( )。
A.0(n)B.D(n2)C.O(1092n)D.0(nl092n)27、 若有定义语句:double x,y,*px,*PY;执⾏了laX=&x;lay=&y;之后,正确的输⼊语句是( )。
if从句练习题

if从句练习题If从句是英语中常用的条件句,用来表达假设、条件或可能性。
理解和正确使用If从句对于提高英语口语和写作水平至关重要。
本文将提供一些If从句的练习题,帮助读者巩固并扩展对该语法结构的理解。
题目一:完成下列If从句1. If it ____(rain) tomorrow, we ____ (stay) at home.2. If I ____ (study) hard, I ____ (pass) the exam.3. What would you do if you ____ (win) a million dollars?4. If you ____ (not hurry), we ____ (miss) the train.5. If he ____ (come) late, we ____ (start) without him.题目二:选择合适的If从句完成句子1. ________ (If / When) the weather is good, we will have a picnic in the park.2. You will succeed ________ (if / unless) you work hard.3. If I _____ (am / were) you, I would apologize to her.4. I will go shopping ________ (if / unless) I finish my homework early.5. ________ (If / When) I see him, I will give him your message.题目三:将下列直述句改写为If从句1. I will pass the exam if I study hard.2. She won't go to the party if she feels tired.3. If I have enough money, I will buy a new car.4. Jack will be late if he misses the bus.5. We won't be able to go swimming if it rains.题目四:按照给定的情境完成句子1. 情境:你迟到了。
if考试题库及答案

if考试题库及答案1. 阅读以下代码段,并选择正确的输出结果。
```pythonx = 10if x > 5:print("x is greater than 5")else:print("x is not greater than 5")```A. x is greater than 5B. x is not greater than 5C. NoneD. Syntax Error正确答案:A2. 考虑以下Python函数,确定它将返回什么值。
```pythondef check_value(value):if value > 0:return "Positive"elif value == 0:return "Zero"else:return "Negative"```当调用`check_value(-5)`时,函数将返回:A. PositiveB. ZeroC. NegativeD. None正确答案:C3. 以下代码段将打印什么?```pythony = 20if y % 2 == 0:print("Even")else:print("Odd")```A. EvenB. OddC. Even OddD. None正确答案:A4. 完成以下代码,使其能够正确地根据输入值打印出“High”,“Medium”或“Low”。
```pythonscore = float(input("Enter a score between 0 and 100: ")) if score >= 90:print("High")elif score >= 70:print("Medium")else:print("Low")该代码段缺少的部分是:A. score的类型转换B. 条件判断C. 输入提示D. 打印语句正确答案:A5. 以下代码段的输出是什么?```pythonz = 15if z > 10:print("z is greater than 10") if z < 20:print("z is less than 20")```A. z is greater than 10B. z is less than 20C. z is greater than 10z is less than 20D. None正确答案:C6. 以下代码段将执行多少次循环?```pythoncounter = 0while counter < 5:counter += 1```B. 5C. 6D. Infinite Loop正确答案:B7. 以下代码段将打印什么?```pythona = 5b = 10if a < b:print("a is less than b") elif a == b:print("a is equal to b") else:print("a is greater than b") ```A. a is less than bB. a is equal to bC. a is greater than bD. None正确答案:A8. 以下代码段将打印什么?```pythonc = 0d = 0if c == d:print("c and d are equal")elif c > d:print("c is greater than d") else:print("c is less than d")```A. c and d are equalB. c is greater than dC. c is less than dD. None正确答案:A9. 以下代码段将打印什么?```pythone = 8f = 2if e % f == 0:print("e is divisible by f") else:print("e is not divisible by f") ```A. e is divisible by fB. e is not divisible by fC. e is divisible by fe is not divisible by fD. None正确答案:A10. 以下代码段将打印什么?```pythong = -3h = -7if g > h:print("g is greater than h") elif g == h:print("g is equal to h") else:print("g is less than h")```A. g is greater than hB. g is equal to hC. g is less than hD. None正确答案:A。
If条件句练习 附答案

If条件句练习:一.用if连接下列句子:1.It rains tomorrow.We won’t go for a picnic.If it rains tomorrow, we won’t go for a picnic.2.The children come home early.They will play in the garden. If the children come home early, they will play in the garden.3.He has a lot of money.He will buy a new car.If he has a lot of money,he will buy a new car.4.I am free.I’ll come here.If I am free, I’ll come here.5.He is rich.He will live abroad.If he is rich, he will live abroad.二.翻译下列句子:1.如果你摔下来,你会伤到自己。
If you fall, you’ll hurt yourself.2.如果我错过了公交车,我就坐车租车。
If I miss the bus, I’ll take a taxi.3.如果你明天病了,你就别去上班了。
If you are sick tomorrow, don’t go to work.4.如果他有很多钱,他就坐飞机去纽约。
If he is rich, he’ll go to New York by plane.5.如果他们给你更多的钱,你会做什么?If they give you more money, what will you do?。
pyif语句练习题

pyif语句练习题Python中的if语句是一种流程控制语句,它提供了一种条件判断的机制。
通过if语句,我们可以根据不同的条件执行不同的代码块。
本文将为你提供一些关于Python中if语句的练习题,帮助你巩固对该语句的理解和运用。
1. 练习题1:比较大小请编写一个程序,接受用户输入的两个数字,然后使用if语句判断两个数字的大小关系,并输出结果。
```pythonnum1 = float(input("请输入第一个数字:"))num2 = float(input("请输入第二个数字:"))if num1 > num2:print("第一个数字大于第二个数字")elif num1 < num2:print("第一个数字小于第二个数字")else:print("两个数字相等")```2. 练习题2:成绩评定请编写一个程序,接受用户输入的一个成绩,然后使用if语句判断该成绩的等级,并输出结果。
假设成绩满分为100分,及格分数为60分,请按照以下标准评定等级:- 90分及以上为优秀- 80分至89分为良好- 70分至79分为中等- 60分至69分为及格- 60分以下为不及格```pythonscore = float(input("请输入成绩:"))if score >= 90:print("优秀")elif score >= 80:print("良好")elif score >= 70:print("中等")elif score >= 60:print("及格")else:print("不及格")```3. 练习题3:奇偶判断请编写一个程序,接受用户输入的一个整数,然后使用if语句判断该整数是奇数还是偶数,并输出结果。
c++if语句选择题

c++if语句选择题1. 下列关于if语句的描述中,正确的是( )。
A. if语句只能用于条件判断B. if语句必须有else子句C. if语句只能有一个条件表达式D. if语句可以嵌套在其他控制语句中2. 下列关于if语句的使用中,错误的是( )。
A. if语句可以在while循环中使用B. if语句可以在for循环中使用C. if语句可以在switch语句中使用D. if语句可以在循环体内部使用3. 下列关于if语句的执行流程中,正确的是( )。
A. 先计算条件表达式的值,再执行if语句块B. 先执行if语句块,再计算条件表达式的值C. 条件表达式的值是true时,才执行if语句块D. 条件表达式的值是false时,才执行if语句块4. 下列关于if语句的语法中,错误的是( )。
A. if (condition) statement;B. if (condition) { statements; }C. if (condition) statement else { statements; }D. if (condition) statement else statement;5. 下列关于if语句的作用域中,正确的是( )。
A. if语句的作用域从if语句开始到if语句结束B. if语句的作用域只包含if语句块中的代码C. if语句的作用域包括if语句块和else语句块中的代码D. if语句的作用域包括整个程序中的代码6. 下列关于if语句的else子句中,错误的是( )。
A. else子句必须与最近的if语句配对使用B. else子句必须放在if语句之后使用C. else子句不能嵌套在其他控制语句中D. else子句可以与if语句分开使用7. 下列关于if语句与switch语句的比较中,正确的是( )。
A. if语句适用于多个条件的情况,而switch语句适用于单个条件的情况B. switch语句的每个case分支相当于一个if-else分支C. switch语句的每个case分支可以包含任意数量的代码,而if-else分支只能包含一个代码块D. switch语句比if-else语句更加高效,因为switch语句使用了跳转表来减少比较次数8. 下列关于嵌套if语句的使用中,错误的是( )。
if条件句练习题

if条件句练习题一、单项选择1. If I _____ where he lived, I _____ a note to him.A. know, would have sentB. had known, would have sentC. know, would sendD. knew, would have sent2. Mary is ill today. If she _____, she _____ absent from school.A. were not ill; wouldn’t beB. had been ill; wouldn’t have beenC. had been ill; should have beenD. hadn’t been ill; could be3. Alan ___ the party if he had gone to London.A. would have missedB. had missedC. would missD. missed4. If you had enough money, what _____?A. will you buyB. would you buyC. would you have boughtD. will you have bought5. If Mr. Young _____ with justice, he _____ sucha wrong thing.A. were treated; wouldn’t doB. had been treated;wouldn’t have doneC. were treated; wouldn’t have doneD. had been treated; wouldn’t do6. What _____ if there _____ no light during the day?A. will happen; wasB. would happen; isC. happens; wereD. would happen; were7. If I knew you were coming, I ___ you at the airport.A. had metB. metC. would meetD. would have met8. If it _____ not for the fact that you _____ ill now, I would surely punish you.A. is; areB. were; wereC. were; areD. was; were9. Many Chinese movie stars now have given up their Chinese nationality. If I were them, I _____ that.A. shouldn’t doB. didn’t doC. hadn’t doneD. won’t do10. If only I ___ to my parents!A. listenedB. had listenedC. should listenD. would listen11.I ___ you some money, but I hadn’t got any then.A. would lendB. would have lentC. could lendD. may have lent12. If Hey had not pulled his cap low over his brow, he _____ by the police.A. might be recognizedB. might have been recognizedC. would have recognizedD. was to have been recognized13. There is a ring at the door. That _____ be the postman, I suppose.A. willB. wouldC. is going toD. was going to14. Look at the dark clouds—there _____ be a storm.A. willB. must have beenC. is going toD. would15. —Why are you taking the pictures down? —I _____ the wall.A. paintB. have just paintedC. am going to paintD. will have painted16. — Can I stay at home tomorrow? —Yes, you can if it_____.A. will snowB. is going to snowC. snowsD. snowed17. I don’t know if he _____ this afternoon. But if he _____, I will tell you.A. will come; will do;B. comes; will doC. will come; doesD. comes; does18. —I thought I asked you to fix the radio.—Oh, I’m sorry. I _____ it right away.A. am to doB. will doC. was about to doD. am going to do19. The WTO can’t live up to its name _____ it does not include a country that is home to one fifth of mankind.A. as long asB. whetherC. ifD. even though20. Ask him to ring me up if you _____ him.A. seeB. sawC. would seeD. will see21. It’s so late. I don’t think he ______ come.A. wouldB. shouldC. is going toD. shall22. If people _____ polluting the air, animals and plants will die soon.A. don’t stopB. didn’t stopC. shall not stopD. haven’t stopped23. If you _____ an interesting day out, ______ the Science Museum.A. want; visitingB. want; visitC. want to; visitD. wanting; visit24. If the pure water is heated to 100 centigrade degrees, it ______ boil.A. is going toB. willC. wouldD. is to25. Is a dictionary available, _____ so, where?A. ifB. if isC. and ifD. and if is二、翻译句子26. If my brother were here, _____________________________________.27. ___________________________,the crops would be saved.28. __________________________________,you would have met him.29. _________________________________,I would have designed a spaceship.30. Had I a lot of money, ______________________________.if_条件状语从句的时态练习及答案_初中习题集I.单项选择1.If you _____ to the party, you’ll have a great time.a. will gob. wentc. god. going2.It will be a long time ____ peter _____ his work.a. since, has finishedb. after, finishesc. when, will finishd. before, finishes.3. what will father _____ us from Japan?a. takeb. bringc. carryd. make4. Weifang is famous ______ kitesa. forb. toc. ond. with5. I____ her the answer if she ____me.a. can tell, will askb. will tell, will askc. would tell, askd. will tell, asks6. – what are you going to do tomorrow?--we’ll go to the library tomorrow if it ___.a. isn’t rainb. rainc. won’t raind. doesn’t rain7.—Do you know when he will come back tomorrow? --sorry, I don’t know. when he ____ back, I’ll tell you.a. comesb. will comec. comed. may come8. what will you do if you _____ to the old folk’s home visit?a. gob. wentc. goingd. will go9. If I eat ____ food, I’ll be very fat.a. too manyb. many tooc. too muchd. much too10.I’ll give the book to him if he ___ here next sunday.a. will comeb. comesc. is comingd. came11. There ____an english film in our school tomorrow.a. is going to haveb. will havec. is going to bed. has12.Could you tell us where ____?a. will the next olympic games heldb. the next olympic games will be heldc. would the next olympic games be heldd. the next olympic games would be held13. When my mother returned last night,I ____ a book.a. readb. am readingc. was readingd. am going to read14. What ____ you ____ when it began to rain?a. do, dob. were, doingc. are, doingd. did, do15. I’ll wake you up when he ____back.a. willb. is going to comec. comesd. comeII、用所给词的适当形式填空1. If you _______ tired, you ______ to have a rest.2. Where _____ he ______ the film if he ________ time?3. If there ____ fewer trees, there _______ more pollution.4. He _____ more casually if he _______ on weekends.5.If marcia _______ alone, she _______ a pet parrot.6. lana _____ a new dress if the old one ____ out of style.7. The twins _____ if they__________ .8. I______ a bake sale if I____ money for education.9. Peter ____ me a beautiful souvenir if he ____ spain.10.If mr. green _______ I am hard- working, my parents _____ glad.11. I______ to the beach if it________ this week.12. ____they ______ a match if the p.e. teacher_______ busy?13. He _______ a letter to his grandparents if he ______ his report card this week.14. If she ______ up late, she _____ the early bus.15. Peter _________ in English if he _______ the exams in peking university. III. 完成句子1.如果他到的晚了会发生什么事情?What _______________ if he _____________ late?2. 如果努力学习,你就会取得好成绩。
python中if语句的简单练习及答案

Python if语句的简单练习及答案if语句是选取要执行的操作,是Python主要的选择工具,代表Python 程序所拥有的大多数逻辑。
if语句是复合语句,同其他复合语句一样,if语句可以包含其他语句1、从键盘输入一个表示年份的正整数,输出此年份是平年还是闰年: 如果能被400整除则为闰年,否则如果被100整除则为平年,否则能被4整除则为闰年,否则为平年;答案如下:year=int(input('请输入一个表示年份的正整数:'))if year%400==0:print('%d为闰年。
'%year)elif year%100==0:print('%d为平年。
'%year)elif year%4==0:print('%d为闰年。
'%year)else:print('%d为平年。
'%year)2、从键盘输入任意三个整数,找出这三个整数中的最大值并输出;答案如下:a=int(input('请输入第一个整数:'))b=int(input('请输入第二个整数:'))c=int(input('请输入第三个整数:'))if a>=b and a>=c:print('%d,%d,%d三个数中最大值为%d;'%(a,b,c,a))elif b>=a and b>=c:print('%d,%d,%d三个数中最大值为%d;'%(a,b,c,b))else:print('%d,%d,%d三个数中最大值为%d;'%(a,b,c,c))3、用input函数输入一个人的身高(m)和体重(kg),并根据BMI公式(体重/身高的平方)计算出BMI指数,并判断BMI等级;判断规则:BMI<18:过轻BMI 18.5~23.9:正常;BMI 24~27.9:超重;BMI 28~32:肥胖;BMI >32 :严重肥胖;答案如下:height=float(input('请输入你的身高(米):'))weight=float(input('请输入你的体重(KG):'))BMI=weight/(height**2)if BMI<18.5:print('过轻')elif BMI<=23.9:print('正常')elif BMI<=27.9:print('过重')elif BMI<=32:print('肥胖')else:print('严重肥胖')4、写一个猜拳游戏,与电脑进行猜拳。
javaif练习题

Java if语句练习题一、基础判断题public class IfExample {public static void main(String args) {int x = 10;if(x > 5) {System.out.println("x is greater than 5"); }}}public class IfExample {public static void main(String args) {int x = 3;if(x < 5) {System.out.println("x is less than 5");} else {System.out.println("x is not less than 5"); }}}public class IfExample {public static void main(String args) {int x = 10;if(x > 5) {System.out.println("x is greater than 5");} else if(x < 5) {System.out.println("x is less than 5");} else {System.out.println("x is equal to 5");}}}二、条件判断编程题4. 编写一个Java程序,判断一个整数是正数、负数还是零。
public class PositiveNegativeZero {public static void main(String args) {// Your here}}5. 编写一个Java程序,根据用户输入的成绩,输出成绩的等级(A, B, C, D, F)。
public class GradeChecker {public static void main(String args) {// Your here}}6. 编写一个Java程序,判断一个年份是否是闰年。
if语句练习题学习资料

i f语句练习题if语句练习题1.以下不正确的if语句形式是______A)if(x>y&&x!=y);B)if(x= =y)x+=y;C)if(x!=y)scanf(“%d”,&x),else scanf(“%d,&y);D)if(x<y){x++;y++;}2.以下运算符中优先级最低的是(1),优先级最高的是(2)A) ?: B)&& C)+ D)! =3.已知int x=10,y=20,z=30;以下语句执行后x,y,z的值是_____ if(x>y)z=x;x=y;y=z;A)x=10,y=20,z=30 B)x=20,y=30,z=30C)x=20,y=30,z=10 D)x=20,y=30,z=204.以下if语句语法正确的是_____A)if(x>0)printf(“%f”,x)else printf(“%f”,-x);B)if(x>0){x=x+y;printf(“%f’,x);}else printf(“%f”,-x);C)if(x>0){x=x+y;printf(“%f”,x);}else printf(“%f”,-x);D)if(x>0){x=x+y;printf(“%f,x);}else printf(“%f”,-x);5.请阅读以下程序:main( ){int a=5,b=0,c=0;if(a=b+c)printf(“* * *\n”);else printf(“$ $ $\n”);}以上程序______A)有语法错不能通过编译 B)可以通过编译但不能通过连接C)输出* * * D)输出$ $ $6.以下程序的运行结果是______main( ){int m=5;if(m++>5)printf(“%d\n”,m);收集于网络,如有侵权请联系管理员删除else printf(“%d\n”,m--);}A) 4 B) 5 C) 6 D) 77.当a=1,b=3,c=5,d=4时,执行完下面一段程序后x的值是______ if(a<b)if(c<d) x=1;elseif(a<c)if(b<d)x=2;else x=3;else x=6;else x=7;A) 1 b) 2 c) 3 d) 68. 有一个函数关系见下表:下面程序段中能正确表示上面关系的是( )A) y=x+1;if(x>=0)if(x==0)y=x;else y=x-1;b) y=x-1;if(x!=0)if(x>0)y=x+1;else y=x;c) if(x<=0)if(x<0)y=x-1;else y=x;else y=x+1;d)y=x;if(x<=0)if(x<0)y=x-1;else y=x+1;9.以下程序的输出结果是______main( ){int a=100,x=10,y=20,okl=5,ok2=0;if(x<y)if(!ok1)a=1;else收集于网络,如有侵权请联系管理员删除if(ok2) a=10;a=-1;printf(“%d\n”,a);}A 1B 0C -1D 值不确定10.以下程序输出结果是_______main( ){int x=2,y=-1,z=2;if(x<y)if(y<0) z=0;else z+=1;printf(“%d\n”,z);A.3B.2C.1D.011.为避免在嵌套的条件语句if-else中产生二义性,C语言规定:else子句总是与___配对.A.缩排位置相同的ifB.其之前最近的ifC.其之后最近的ifD.同一行上的if12.以下不正确的语句为______A.if(x>y);B.if(x=y)&&(x! =0) x+=y; C,if(x! =y)scanf(“%d”,&x);else scanf(“%d”,&y);D.if(x<y){x++;y++;}12.阅读以下程序#include<stdio.h>main( ){float a, b;scanf(“%f”,&a);if(a<0.0)b=0.0;else if((a<0.5)&&(a!=2.0))b=1.0/(a+2.0);else if(a<10.0)b=1.0/a;else b=10.0;printf(“%f\n”,b);}若运行时输入2.0<回车>,则上面程序的输出结果是_____A)0.000000 B)0.500000 C)1.000000 D)0.25000013.若运行时输入:16<回车>,则以下程序的运行结果是( ) #include<stdio.h>main( ){int year;printf(“Input you year:”);scanf(“%d”,&year);收集于网络,如有侵权请联系管理员删除if(year>=18)printf(“you$4.5yuan/xiaoshi”);else printf(“your$3.0yuan/xiaoshi”);}14.若运行时输入:2<回车>,则以下程序的运行结果是( )#include<stdio.h>main( ){char class;printf(“enter 1for 1stclass post or 2 for 2nd post”); scanf(“%c”,&class);if(class= =’1’) printf(“1st class postage is 19p”); else printf(“2nd class postage is 14p”);}15.若运行时输入:4.4<回车>,则以下程序的运行结果是() #include<stdio.h>main( ){float costprice,sellingprice;printf(“enter cost price $:”);scanf(“%f”,&costprice);if(costprice>=5){sellingprice=costprice+costprice*0.25;printf(“selling price(0.25)$%6.2f”,sellingprice);}else{sellingprice=costprice+costprice*0.30;printf(“selling price(0.30)$%6.2f”,sellingprice);}}16.以下程序的运行结果是( )main( ){ if(2*2= =5<2*2= =4) printf(“T”);else printf(“F”);}17.请阅读以下程序:main( ){int t,h,m;scanf(“%d”,&t);h=(t/100)%12;if(h= =0)h=12;printf(“%d:”,h);m=t%100;if(m<10)printf(“0”);printf(“%d”,m);if(t<1200||t= =2400)printf(“AM”);else printf(“PM”);}收集于网络,如有侵权请联系管理员删除若运行时输入:1605<回车>时,程序的运行结果是( )18.以下程序实现:输入圆的半径r和运行标志m,按照运行标志进行指定计算.请在( )内填入正确的内容.标志运算a 面积c 周长b 二者均计算#define pi 3.14159main( ){char m;float r,c,a;printf(“input mark a c or b&&r\n”);scanf(“%c%f”,&m,&r);if( 1 ){a=pi*r*r;printf(“area is %f”,a);}if( 2 ){c=2*pi*r;printf(“circle is %f”,c);}if( 3 ){a=pi*r*r;c=2*pi*r;printf(“area&&circle are%f%f”,a,c);}} 19.若运行时输入:5999<回车>,则以下程序的运行结果(保留小数后一位)是( )main( ){int x;float y;scanf(“%d”,&x);if(x>=0&&x<=2999)y=18+0.12*x;if(x>=3000&&x<=5999)y=36+0.6*x;if(x>=6000&&x<=10000)y=54+0.3*x;printf(“%6.1f”,y);}20.以下程序实现输出x,y,z三个数中的最大者.请在( )添入正确内容.main( ){int x=4,y=6,z=7;int ( 1 )if( 2 )u=x;else u=y;if( 3 )v=u;else v=z;printf(“v=%d”,v);}21.以下程序实现:输入三个整数,按从大到小的顺序进行输出.请在( )内填入正确内容main( )收集于网络,如有侵权请联系管理员删除{int x,y,z,c;scanf(“%d%d%d”,&x,&y,&z);if( 1 ){c=y;y=z;z=c;}if( 2 ){c=x;x=z;z=c;}if( 3 ){c=x;x=y;y=c;}printf(“%d,%d,%d”,x,y,z);}22.以下程序对输入的两个整数,按从大到小顺序输出.请在( )内填正确内容. main ( ){int x,y,z;scanf(“%d,%d,”,&x,&y);if( 1 ){z=x;(2)}printf(“%d,%d”,x,y);}23.以下程序对输入的一个小写字母,将字母循环后移5个位置后输出.如’a’变成’f’,’w’变成’b’.请在( )填入正确内容#include “stdio.h”main( ) {char c;c=getchar( );if(c>=’a’&&c<=’u’)( 1 )else if(c>=’v’&&c<=’z’)( 2 )putchar(c);}24.输入一个字符,如果它是一个大写字母,则把它变成小写,如果是小写,则变成大写,其他字符不变,请在( )填正确内容main ( ){char ch;scanf(“%c”,&ch);if( 1 )ch=ch+32;else if(ch>=’a’&&ch<=’z’)(2)printf(“%c”,ch);}25.以下程序的运行结果是( )main( ){int a,b,c;int s,w,t;s=w=t=0;a=-1,b=3,c=3;if(c>0)s=a+b;收集于网络,如有侵权请联系管理员删除if(a<=0){if(b>0)if(c<=0)w=a-b;}else if(c>0)w=a-b;else t=c;printf(“%d%d%d”,s,w,t);} 26.以下程序的运行结果是( ) main( ){int a,b,c,d,x;a=c=0;b=1;d=20;if(a)d=d-10;else if(! b)if(! c)x=15;else x=25;printf(“%d\n”,d);}27.以下程序的运行结果是( ) #include<stdio.h>main( ){int x,y=1,z;if(y!=0)x=5;printf(“\t%d\n”,x);if(y= =0)x=4;else x=5;printf(“\t%d\n”,x);x=1;if(y<0)if(y>0)x=4;else x=5;printf(“\t%d\n”,x);}28.以下程序的运行结果是( )#include<stdio.h>main( ){int x,y=-2,z=0;if((z=y)<0)x=4;else if(y= =0)x=5;else x=6;printf(“\t%d\t%d\n”,x,z);if(z=(y= =0))x=5;收集于网络,如有侵权请联系管理员删除x=4;printf(“\t%d\t%d\n”,x,z);if(x=z=y)x=4;printf(“\t%d\t%d\n”,x,z);}29.阅读下面程序:main ( ){int s,t,a,b;scanf(“%d,%d”,&a,&b);s=1;t=1;if(a>0)s=s+1;if(a>b)t=s+t;else if(a= =b)t=5;else t=2*s;printf(“s=%d,t=%d”,s,t);}为使输出结果t=4,输入量a和b应满足的条件是( ) 30.请阅读下面程序:main( ){int s ,t,a,b;scanf(“%d,%d”,&a,&b);s=1;t=1;if(a>0)s=s+1;if(a>b)t=s+t;else if(a= =b)t=5;else t=2*s;printf(“s=%d,t=%d”,s,t);}为使输出结果s=1,t=5,输入量a和b应满足条件是( )31.下面程序根据以下函数关系,对输入的每个x值,计算出y值,在( )填正确内容main( ){int x,y;scanf(“%d,&x);if(1)y=x*(x+2);else if(2)y=2*x;else if(x<=-1)y=x-1;else( 3 );收集于网络,如有侵权请联系管理员删除if(y!=-1)printf(“%d”,y);else printf(“error”);}32.下面程序根据以下函数关系,对输入的每个x值,计算出相应的y值.在( ) 填正确内容#include “math.h”main( ){int x,a;float y;scanf(“%d%d”,&x,&a);if( 1 )y=0;else if( 2 )y=sqrt(a*a-x*x);else y=x;printf(“%f”,y);}33.以下程序的功能是计算一元二次方程ax2+bx+c=0的根,在( )填正确内容#include “math.h”main( ){float a,b,c,t,disc,twoa,term1,term2;printf(“enter a,b,c:”);scanf(“%f%f%f”,&a,&b,&c);if( 1 )if( 2 )printf(“no answer due to input error\n”);else printf(“the single root is%f\n”,-c/b);else{disc=b*b-4*a*c;twoa=2*a;terml=-b/twoa;t=abs(disc);term2=sqrt(t)/twoa;if(3)printf(“complex root\n real part=%fimag part=%f\n”, terml,term2);else printf(“real roots\n rootl=%froot2=%f\n”,terml+term2,term1-term2);}} 34.以下程序根据输入的三角形的三边判断是否能组成三角形,若可以则输出它的面积和三角形的类型.在( )填正确内容.#include“math.h”main( ){float a,b,c;收集于网络,如有侵权请联系管理员删除float s,area;scanf(“%f %f %f”,&a,&b,&c);if( [1] ){s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c));printf(“%f”,area);if( [2] )printf(“等边三角形”);else if( [3] )printf(“等腰三角形”);else if((a*a+b*b= =c*c)| |(a*a+c*c= =b*b)| |(b*b+c*c= =a*a) )printf(“直角三角形”);else printf(“一般三角形”);}else printf(“不能组成三角形”);}35. 某邮局对邮寄包裹有如下规定:若包裹的长宽高任一尺寸超过1米或重量超过30千克,不予邮寄;对可以邮寄的包裹每件收手续费0.2元,再加上根据下表按重量wei计算的资料:重量(千克) 收费标准(元/公斤) wei<=10 0.8010<wei<=20 0.7520<wei<=30 0.70请在程序的[ ]内填入正确的内容.main( ){float len,wei,hei,wid,mon,r;scanf(“%f %f %f %f”,&len,&wid,&hei,&wei);if(len>1| |wid>1| |hei>1| |wei>30)[ 1 ];else if(wei<10) r=0.8;else if(wei<=20) r=0.75;else if(wei<=30)[ 2 ];if(r= =-1)printf(“error\n”):else {[ 3 ];printf(“%f”,mon);} }36.以下程序的功能是判断输入的年份是否是闰年.请在[ ]内填入正确的内容.main( ){int y,f;scanf(“%d”,&y);if(y%400= =0) f=1;else if( [1] ) f=1;else [2] ;if(f)printf(“%d is”,y);else printf(“%d is not”,y);printf(“a leap year\n”);}37.有四个数a, b, c, d,要求按从大到小的顺序输出.请在[ ]内填入正确内容main( ){int a,b,c,d,t;scanf(“%d %d %d %d”,&a,&b,&c,&d);if(a<b){t=a;a=b;b=t;}if ([1]){t=c;c=d;d=t;}if(a<c){t=a;a=c;c=t;}if([2]){t=b;b=c;c=t;}if(b<d){t=b;b=d;d=t;}if(c<d){t=c;c=d;d=t;}printf(“%d %d %d %d\n”,a,b,c,d);}38.以下程序的运行结果是__main( ){int a=2,b=3,c;c=a;if(a>b)c=1;else if(a= =b)c=0;else c=-1;printf(“%d\n”,c);}39.编制程序要求输入整数a和b,若a2+b2大于100,则输出a2+b2百位以上数字,否则输出两数之和.40.试编程判断输入的正整数是否既是5又是7的整倍数.若是,则输出yes,否则输出no41.编程序:根据以下函数关系,对输入的每个x值,计算出相应的y值42.编程实现:输入一个整数,判断它能否被3,5,7整除,并输出以下信息之一(1)能同时被3,5,7整除(2)能被其中两个数整除(要指出那两个数)(3)能被其中一个数整除(指出那一个)(4)不能被3,5,7任一个整除1、C2、(1)A (2)C3、B4、C5、D6、C7、B8、C9、C 10、B 11、A 12、B 12、B13、your$3.0yuan/xiaoshi14、2nd class postage is 14p15、selling price(0.30)$ 5.72 (注意:5.72前有2个空格)16、F17、4:05PM18、(1) m=='a' (2) m=='c' (3) m=='b'19、3635.4。
if条件句练习题及答案

if条件句练习题及答案If条件句是英语语法中的重要部分,它用于表达假设、推理和可能性。
在日常交流中,我们经常使用if条件句来表达自己的观点、提出建议或者进行推测。
下面,我将给大家介绍一些if条件句的练习题及答案,希望对大家的英语学习有所帮助。
练习题一:完成下列if条件句。
1. If it rains tomorrow, _______________.2. If I had more money, _______________.3. If she studies hard, _______________.4. If I were you, _______________.5. If they arrive late, _______________.答案一:1. we will stay at home.2. I would buy a new car.3. she will pass the exam.4. I would apologize to her.5. they will miss the beginning of the movie.练习题二:根据上下文,选择正确的if条件句。
1. A: I don't have an umbrella. B: _______________.a. If it rains, I will lend you mine.b. If it rains, I would lend you mine.2. A: I am tired. B: _______________.a. If you go to bed early, you will feel better.b. If you went to bed early, you would feel better.3. A: The concert starts at 8 o'clock. B: _______________.a. If we leave now, we will arrive on time.b. If we left now, we would arrive on time.4. A: He is always late for work. B: _______________.a. If he doesn't leave earlier, he will be late again.b. If he didn't leave earlier, he would be late again.5. A: I have a headache. B: _______________.a. If you take some medicine, you will feel better.b. If you took some medicine, you would feel better.答案二:1. a. If it rains, I will lend you mine.2. a. If you go to bed early, you will feel better.3. a. If we leave now, we will arrive on time.4. a. If he doesn't leave earlier, he will be late again.5. a. If you take some medicine, you will feel better.练习题三:根据给出的条件,完成if条件句。
if-练习题

1. If he hard, he will get good grades.A. studyB. studiesC. will studyD. studied2. I want to know if Mary to the party tomor row.A. goB. wentC. will goD. goes3. Everyone must dress up. If you , they won’t let you in.A. don’tB. won’tC. can’tD. mustn’t4. Mary will go to Sanya if she a five-day trip.A. haveB. hadC. will haveD. has5. If he comes late, he will miss the train.A. andB. soC. /D. or1.If you ________(feel) tired, you _________ (have) to have a rest.2. Where _____ he ____(see) the film if he _________(have) time?3. If there ____(be) fewer trees, there _______( be) more pollution.4. He ___(dress) more casually if he ___( not work) on weekends.5. If Marcia _______(live) alone, she _______( keep) a pet parrot.6. Lana _____ buy) a new dress if the old one ____(be) out of style.7.The twins _______(fight) if they__________(argue).8. I ______(have) a bake sale if I ____(need) money for education.9. Peter ____( send) me a beautiful souvenir if he ____(tour) Spain.10. If Mr Green _______ (say) I am hard- working, my parents ___( feel) glad.11.I ______(go) to the beach if it________ ( not rain) this week.12. _____they ___( have) a match if the P.E. teacher __(be) busy?13.He ____(write) a letter to his grandparents if he ____(get) his report card this week.14. If she ______(get) up late, she _____ ( not catch) the early bus.。
if练习题

if练习题在编程中,`if` 语句是一种基本的控制流语句,它允许程序在满足特定条件时执行一段代码。
以下是一些 `if` 练习题,旨在帮助初学者掌握 `if` 语句的使用。
1. 基础条件判断:编写一个程序,要求用户输入一个数字,然后判断这个数字是正数、负数还是零,并打印相应的信息。
2. 年龄判断:写一个程序,要求用户输入他们的年龄。
如果年龄小于18岁,打印“未成年”;如果年龄在18岁到65岁之间,打印“成年人”;如果年龄大于65岁,打印“老年人”。
3. 成绩判定:编写一个程序,要求用户输入一个成绩(0-100分)。
如果成绩大于等于90分,打印“A”;如果成绩在80到89分之间,打印“B”;如果成绩在70到79分之间,打印“C”;如果成绩在60到69分之间,打印“D”;如果成绩小于60分,打印“不及格”。
4. 闰年判断:写一个程序,要求用户输入一个年份,然后判断这一年是否是闰年。
闰年的条件是:能被4整除但不能被100整除,或者能被400整除。
5. 温度转换:编写一个程序,要求用户输入摄氏温度,然后打印对应的华氏温度。
转换公式为:华氏度 = (摄氏度 * 9/5) + 32。
6. 数字比较:编写一个程序,要求用户输入两个数字。
然后根据输入的数字,打印出“第一个数字更大”、“第二个数字更大”或者“两个数字相等”。
7. 奇偶数判断:写一个程序,要求用户输入一个整数。
判断这个整数是奇数还是偶数,并打印相应的信息。
8. 购物优惠:编写一个程序,要求用户输入他们购买的商品数量和单价。
如果购买数量超过10个,打印出“享受10%的折扣”。
9. 登录验证:编写一个程序,要求用户输入用户名和密码。
如果用户名是"admin"且密码是"password",则打印“登录成功”;否则打印“用户名或密码错误”。
10. 时间判断:编写一个程序,要求用户输入当前的小时数。
如果时间在6点到12点之间,打印“早上好”;如果时间在12点到18点之间,打印“下午好”;如果时间在18点到22点之间,打印“晚上好”;如果时间在22点到6点之间,打印“晚安”。
最新if语句练习题

最新if语句练习题精品文档精品文档IF语句练习题一、选择题:1.赋值语句x=x+1的正确含义是(A) 变量x与x+1的值相等(B) 将变量x的值加到x+1中去(C) 将变量x的值加1后赋值给变量x(D) 变量x的值为12.VB语句If i=1 Then j=1,下列说法正确的是(A)i=1和j=1均为赋值语句(B)i=1和j=1均为关系表达式(C)i=1为关系表达式,j=1均为赋值语句(D)i=1为赋值语句,j=1为关系表达式二、填空题:1.有如下VB程序段:该程序段运行后,变量c的值为____________。
a = "English"b = "f"c = b + Mid(a, 5, 3)2.有如下VB程序段:该程序段运行后,在文本框Text1上显示的是____________。
t = 130h = 170b = (h - 100) * 2If t > b ThenText1.text="超标"‘显示"超标"ElseText1.text="正常" ‘显示"正常"End If3.有如下VB程序段:该程序段运行后,在文本框Text1上显示的是____________。
w = 9a = 90b = 50If w > 10 Or a * b > 4000 ThenText1.text = "托运"ElseText1.text = "携带"End If 4. 有如下VB程序段:该程序段运行后,在文本框T ext1上显示的是____________。
a = 10b = 6c = 5If a + b > c And b + c > a And c + a > b Then Text1.text = "YES"ElseText1.text = "NO"End If5. 有如下VB程序段:该程序段运行后,在文本框Text1上显示的是____________。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
i f语句练习题if语句练习题1.以下不正确的if语句形式是______A)if(x>y&&x!=y);B)if(x= =y)x+=y;C)if(x!=y)scanf(“%d”,&x),else scanf(“%d,&y);D)if(x<y){x++;y++;}2.以下运算符中优先级最低的是(1),优先级最高的是(2)A) ?: B)&& C)+ D)! =3.已知int x=10,y=20,z=30;以下语句执行后x,y,z的值是_____ if(x>y)z=x;x=y;y=z;A)x=10,y=20,z=30 B)x=20,y=30,z=30C)x=20,y=30,z=10 D)x=20,y=30,z=204.以下if语句语法正确的是_____A)if(x>0)printf(“%f”,x)else printf(“%f”,-x);B)if(x>0){x=x+y;printf(“%f’,x);}else printf(“%f”,-x);C)if(x>0){x=x+y;printf(“%f”,x);}else printf(“%f”,-x);D)if(x>0){x=x+y;printf(“%f,x);}else printf(“%f”,-x);5.请阅读以下程序:main( ){int a=5,b=0,c=0;if(a=b+c)printf(“* * *\n”);else printf(“$ $ $\n”);}以上程序______A)有语法错不能通过编译 B)可以通过编译但不能通过连接C)输出* * * D)输出$ $ $6.以下程序的运行结果是______main( ){int m=5;if(m++>5)printf(“%d\n”,m);收集于网络,如有侵权请联系管理员删除else printf(“%d\n”,m--);}A) 4 B) 5 C) 6 D) 77.当a=1,b=3,c=5,d=4时,执行完下面一段程序后x的值是______ if(a<b)if(c<d) x=1;elseif(a<c)if(b<d)x=2;else x=3;else x=6;else x=7;A) 1 b) 2 c) 3 d) 68. 有一个函数关系见下表:下面程序段中能正确表示上面关系的是( )A) y=x+1;if(x>=0)if(x==0)y=x;else y=x-1;b) y=x-1;if(x!=0)if(x>0)y=x+1;else y=x;c) if(x<=0)if(x<0)y=x-1;else y=x;else y=x+1;d)y=x;if(x<=0)if(x<0)y=x-1;else y=x+1;9.以下程序的输出结果是______main( ){int a=100,x=10,y=20,okl=5,ok2=0;if(x<y)if(!ok1)a=1;else收集于网络,如有侵权请联系管理员删除if(ok2) a=10;a=-1;printf(“%d\n”,a);}A 1B 0C -1D 值不确定10.以下程序输出结果是_______main( ){int x=2,y=-1,z=2;if(x<y)if(y<0) z=0;else z+=1;printf(“%d\n”,z);A.3B.2C.1D.011.为避免在嵌套的条件语句if-else中产生二义性,C语言规定:else子句总是与___配对.A.缩排位置相同的ifB.其之前最近的ifC.其之后最近的ifD.同一行上的if12.以下不正确的语句为______A.if(x>y);B.if(x=y)&&(x! =0) x+=y; C,if(x! =y)scanf(“%d”,&x);else scanf(“%d”,&y);D.if(x<y){x++;y++;}12.阅读以下程序#include<stdio.h>main( ){float a, b;scanf(“%f”,&a);if(a<0.0)b=0.0;else if((a<0.5)&&(a!=2.0))b=1.0/(a+2.0);else if(a<10.0)b=1.0/a;else b=10.0;printf(“%f\n”,b);}若运行时输入2.0<回车>,则上面程序的输出结果是_____A)0.000000 B)0.500000 C)1.000000 D)0.25000013.若运行时输入:16<回车>,则以下程序的运行结果是( ) #include<stdio.h>main( ){int year;printf(“Input you year:”);scanf(“%d”,&year);收集于网络,如有侵权请联系管理员删除if(year>=18)printf(“you$4.5yuan/xiaoshi”);else printf(“your$3.0yuan/xiaoshi”);}14.若运行时输入:2<回车>,则以下程序的运行结果是( )#include<stdio.h>main( ){char class;printf(“enter 1for 1stclass post or 2 for 2nd post”); scanf(“%c”,&class);if(class= =’1’) printf(“1st class postage is 19p”); else printf(“2nd class postage is 14p”);}15.若运行时输入:4.4<回车>,则以下程序的运行结果是() #include<stdio.h>main( ){float costprice,sellingprice;printf(“enter cost price $:”);scanf(“%f”,&costprice);if(costprice>=5){sellingprice=costprice+costprice*0.25;printf(“selling price(0.25)$%6.2f”,sellingprice);}else{sellingprice=costprice+costprice*0.30;printf(“selling price(0.30)$%6.2f”,sellingprice);}}16.以下程序的运行结果是( )main( ){ if(2*2= =5<2*2= =4) printf(“T”);else printf(“F”);}17.请阅读以下程序:main( ){int t,h,m;scanf(“%d”,&t);h=(t/100)%12;if(h= =0)h=12;printf(“%d:”,h);m=t%100;if(m<10)printf(“0”);printf(“%d”,m);if(t<1200||t= =2400)printf(“AM”);else printf(“PM”);}收集于网络,如有侵权请联系管理员删除若运行时输入:1605<回车>时,程序的运行结果是( )18.以下程序实现:输入圆的半径r和运行标志m,按照运行标志进行指定计算.请在( )内填入正确的内容.标志运算a 面积c 周长b 二者均计算#define pi 3.14159main( ){char m;float r,c,a;printf(“input mark a c or b&&r\n”);scanf(“%c%f”,&m,&r);if( 1 ){a=pi*r*r;printf(“area is %f”,a);}if( 2 ){c=2*pi*r;printf(“circle is %f”,c);}if( 3 ){a=pi*r*r;c=2*pi*r;printf(“area&&circle are%f%f”,a,c);}} 19.若运行时输入:5999<回车>,则以下程序的运行结果(保留小数后一位)是( )main( ){int x;float y;scanf(“%d”,&x);if(x>=0&&x<=2999)y=18+0.12*x;if(x>=3000&&x<=5999)y=36+0.6*x;if(x>=6000&&x<=10000)y=54+0.3*x;printf(“%6.1f”,y);}20.以下程序实现输出x,y,z三个数中的最大者.请在( )添入正确内容.main( ){int x=4,y=6,z=7;int ( 1 )if( 2 )u=x;else u=y;if( 3 )v=u;else v=z;printf(“v=%d”,v);}21.以下程序实现:输入三个整数,按从大到小的顺序进行输出.请在( )内填入正确内容main( )收集于网络,如有侵权请联系管理员删除{int x,y,z,c;scanf(“%d%d%d”,&x,&y,&z);if( 1 ){c=y;y=z;z=c;}if( 2 ){c=x;x=z;z=c;}if( 3 ){c=x;x=y;y=c;}printf(“%d,%d,%d”,x,y,z);}22.以下程序对输入的两个整数,按从大到小顺序输出.请在( )内填正确内容. main ( ){int x,y,z;scanf(“%d,%d,”,&x,&y);if( 1 ){z=x;(2)}printf(“%d,%d”,x,y);}23.以下程序对输入的一个小写字母,将字母循环后移5个位置后输出.如’a’变成’f’,’w’变成’b’.请在( )填入正确内容#include “stdio.h”main( ) {char c;c=getchar( );if(c>=’a’&&c<=’u’)( 1 )else if(c>=’v’&&c<=’z’)( 2 )putchar(c);}24.输入一个字符,如果它是一个大写字母,则把它变成小写,如果是小写,则变成大写,其他字符不变,请在( )填正确内容main ( ){char ch;scanf(“%c”,&ch);if( 1 )ch=ch+32;else if(ch>=’a’&&ch<=’z’)(2)printf(“%c”,ch);}25.以下程序的运行结果是( )main( ){int a,b,c;int s,w,t;s=w=t=0;a=-1,b=3,c=3;if(c>0)s=a+b;收集于网络,如有侵权请联系管理员删除if(a<=0){if(b>0)if(c<=0)w=a-b;}else if(c>0)w=a-b;else t=c;printf(“%d%d%d”,s,w,t);} 26.以下程序的运行结果是( ) main( ){int a,b,c,d,x;a=c=0;b=1;d=20;if(a)d=d-10;else if(! b)if(! c)x=15;else x=25;printf(“%d\n”,d);}27.以下程序的运行结果是( ) #include<stdio.h>main( ){int x,y=1,z;if(y!=0)x=5;printf(“\t%d\n”,x);if(y= =0)x=4;else x=5;printf(“\t%d\n”,x);x=1;if(y<0)if(y>0)x=4;else x=5;printf(“\t%d\n”,x);}28.以下程序的运行结果是( )#include<stdio.h>main( ){int x,y=-2,z=0;if((z=y)<0)x=4;else if(y= =0)x=5;else x=6;printf(“\t%d\t%d\n”,x,z);if(z=(y= =0))x=5;收集于网络,如有侵权请联系管理员删除x=4;printf(“\t%d\t%d\n”,x,z);if(x=z=y)x=4;printf(“\t%d\t%d\n”,x,z);}29.阅读下面程序:main ( ){int s,t,a,b;scanf(“%d,%d”,&a,&b);s=1;t=1;if(a>0)s=s+1;if(a>b)t=s+t;else if(a= =b)t=5;else t=2*s;printf(“s=%d,t=%d”,s,t);}为使输出结果t=4,输入量a和b应满足的条件是( ) 30.请阅读下面程序:main( ){int s ,t,a,b;scanf(“%d,%d”,&a,&b);s=1;t=1;if(a>0)s=s+1;if(a>b)t=s+t;else if(a= =b)t=5;else t=2*s;printf(“s=%d,t=%d”,s,t);}为使输出结果s=1,t=5,输入量a和b应满足条件是( )31.下面程序根据以下函数关系,对输入的每个x值,计算出y值,在( )填正确内容main( ){int x,y;scanf(“%d,&x);if(1)y=x*(x+2);else if(2)y=2*x;else if(x<=-1)y=x-1;else( 3 );收集于网络,如有侵权请联系管理员删除if(y!=-1)printf(“%d”,y);else printf(“error”);}32.下面程序根据以下函数关系,对输入的每个x值,计算出相应的y值.在( ) 填正确内容#include “math.h”main( ){int x,a;float y;scanf(“%d%d”,&x,&a);if( 1 )y=0;else if( 2 )y=sqrt(a*a-x*x);else y=x;printf(“%f”,y);}33.以下程序的功能是计算一元二次方程ax2+bx+c=0的根,在( )填正确内容#include “math.h”main( ){float a,b,c,t,disc,twoa,term1,term2;printf(“enter a,b,c:”);scanf(“%f%f%f”,&a,&b,&c);if( 1 )if( 2 )printf(“no answer due to input error\n”);else printf(“the single root is%f\n”,-c/b);else{disc=b*b-4*a*c;twoa=2*a;terml=-b/twoa;t=abs(disc);term2=sqrt(t)/twoa;if(3)printf(“complex root\n real part=%fimag part=%f\n”, terml,term2);else printf(“real roots\n rootl=%froot2=%f\n”,terml+term2,term1-term2);}} 34.以下程序根据输入的三角形的三边判断是否能组成三角形,若可以则输出它的面积和三角形的类型.在( )填正确内容.#include“math.h”main( ){float a,b,c;收集于网络,如有侵权请联系管理员删除float s,area;scanf(“%f %f %f”,&a,&b,&c);if( [1] ){s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c));printf(“%f”,area);if( [2] )printf(“等边三角形”);else if( [3] )printf(“等腰三角形”);else if((a*a+b*b= =c*c)| |(a*a+c*c= =b*b)| |(b*b+c*c= =a*a) )printf(“直角三角形”);else printf(“一般三角形”);}else printf(“不能组成三角形”);}35. 某邮局对邮寄包裹有如下规定:若包裹的长宽高任一尺寸超过1米或重量超过30千克,不予邮寄;对可以邮寄的包裹每件收手续费0.2元,再加上根据下表按重量wei计算的资料:重量(千克) 收费标准(元/公斤) wei<=10 0.8010<wei<=20 0.7520<wei<=30 0.70请在程序的[ ]内填入正确的内容.main( ){float len,wei,hei,wid,mon,r;scanf(“%f %f %f %f”,&len,&wid,&hei,&wei);if(len>1| |wid>1| |hei>1| |wei>30)[ 1 ];else if(wei<10) r=0.8;else if(wei<=20) r=0.75;else if(wei<=30)[ 2 ];if(r= =-1)printf(“error\n”):else {[ 3 ];printf(“%f”,mon);} }36.以下程序的功能是判断输入的年份是否是闰年.请在[ ]内填入正确的内容.main( ){int y,f;scanf(“%d”,&y);if(y%400= =0) f=1;else if( [1] ) f=1;else [2] ;if(f)printf(“%d is”,y);else printf(“%d is not”,y);printf(“a leap year\n”);}37.有四个数a, b, c, d,要求按从大到小的顺序输出.请在[ ]内填入正确内容main( ){int a,b,c,d,t;scanf(“%d %d %d %d”,&a,&b,&c,&d);if(a<b){t=a;a=b;b=t;}if ([1]){t=c;c=d;d=t;}if(a<c){t=a;a=c;c=t;}if([2]){t=b;b=c;c=t;}if(b<d){t=b;b=d;d=t;}if(c<d){t=c;c=d;d=t;}printf(“%d %d %d %d\n”,a,b,c,d);}38.以下程序的运行结果是__main( ){int a=2,b=3,c;c=a;if(a>b)c=1;else if(a= =b)c=0;else c=-1;printf(“%d\n”,c);}39.编制程序要求输入整数a和b,若a2+b2大于100,则输出a2+b2百位以上数字,否则输出两数之和.40.试编程判断输入的正整数是否既是5又是7的整倍数.若是,则输出yes,否则输出no41.编程序:根据以下函数关系,对输入的每个x值,计算出相应的y值42.编程实现:输入一个整数,判断它能否被3,5,7整除,并输出以下信息之一(1)能同时被3,5,7整除(2)能被其中两个数整除(要指出那两个数)(3)能被其中一个数整除(指出那一个)(4)不能被3,5,7任一个整除1、C2、(1)A (2)C3、B4、C5、D6、C7、B8、C9、C 10、B 11、A 12、B 12、B13、your$3.0yuan/xiaoshi14、2nd class postage is 14p15、selling price(0.30)$ 5.72 (注意:5.72前有2个空格)16、F17、4:05PM18、(1) m=='a' (2) m=='c' (3) m=='b'19、3635.4。