You are on page 1of 1

Birla Institute of Technology & Science, Pilani Second Semester 2013-2014, Computer Programming [CS F111] Week #4 Tutorial

Sheet 1 Topics to be discussed: Relational, Equality and Logical Operators Conditional Control Structure [5 min] Summarizing the topic on relational and logical operators with an emphasis short circuit evaluation. [5 min] Write a program to accept a character from the user and display a message if the input character is a vowel. [10 min] Write a program to accept a number from the user. If the number is in the range [1,999], display an appropriate message. Now rewrite the logical expression using a different logical operator. [15 min] Precedence of operators with relational, logical operators with an example highlighting the step-by step evaluation of the following expressions. [Assume a=5, b=10 and c=15, flag=1] a != 7 && flag || c >= 6 !(b <=12) && a % 2 == 0 !(a > 5 || c < a + b )

[15 min] Emphasis on the need of conditional control structure and example a) Write a program that prompts the user to enter a number. If the user enters a number divisible by 5, print a message as follows: The number is divisible by 5. If the number is not divisible by 5, there is no need to print the message, b) Modify the expression in the above control structure to check if the number is divisible by both 5 and 3 and change the message to a multi-line message as follows: The number is divisible by 5. The number is divisible by 3 as well. c) Modify the code segment a) to display another message when the number is not divisible by 5.

You might also like