《程序设计I实验.ppt》由会员分享,可在线阅读,更多相关《程序设计I实验.ppt(7页珍藏版)》请在第壹文秘上搜索。
1、程序设计I实验实验5:选择语句(下)实验目的 掌握布尔型变量的定义和用法 掌握关系运算符、逻辑运算符的使用 巩固if-else分支结构的使用 练习switch语句的用法实验内容1 Using the&and|operatorWrite a program that reads an integer n and determines whether it is divisible by 5 and 6,whether it is divisible by 5 or 6,and whether it is divisible by 5 or 6,but not both.InputAn integ
2、er n in one line.OutputThe result in 3 lines like the Sample Output.Sample Input10 Sample OutputIs 10 divisible by 5 and 6?falseIs 10 divisible by 5 or 6?trueIs 10 divisible by 5 or 6,but not both?True实验内容2Find the max and min读入若干整数,找出其中的最大值和最小值。Input输入的第一行为一个数N,表示即将输入的数字的个数(2=N=1000)。接下来有N行,每一行一个整数
3、a(0=a 32767).Output输出仅包括一行,格式如下max min其中max为输入的N个数中的最大值,min为输入的N个数中的最小值。Sample Input212Sample Output1实验内容3 Sorting three integersWrite a program that reads three integers num1,num2,num3,and sort the numbers so that num1=num2=num3.InputThree integers num1,num2,num3 in one line.OutputThe sorted three
4、numbers seperated by one blank in one line.Sample Input1 3 2 Sample Output1 2 3实验内容4Finding the number of days in a monthWrite a program that reads month and year,then displays the number of days in the month.For example,if the user entered month 2 and year 2000,the program should display that Febru
5、ary 2000 has 29 days.If the user entered month 3 and year 2005,the program should display that March 2005 has 31 days.InputTwo numbers a,b(seperated by one blank),a for the year,b for the month.OutputThe result in one line.Sample Input2000 2Sample OutputFebruary 2000 has 29 daysHint分别用If else 和 switch实现。结束!