Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

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

Sheet 2 [35 min] Topics to be discussed: Nested Conditional Construct Switch Statement [5 mins] Review of recorded content on nested ifs and switch statements. Explain switch clearly. [15 min] Write a program that takes a character indicating a color from the user and (using switch statement) displays whether that color is present in the rainbow. If its present, then display the full color as well. Rewrite the program using the if-else if construct. Emphasis is on switch statement, break with switch, and converting switch to if else.

[10mins] Write a program to find the maximum of three numbers using if-else construct. [5 min] Find the output of the following codes, assuming the integer variables contain initially the values x = 25, i = 10, j = 8, z = 18, k = 3 if(x == 25) if( i> j) if( k > 5) z = k; else z = 20; printf( The value of z is %d , z); With which statement does elsegets associated with inner if or the outer if? Modify the above code in such a way that the code is no more misleading, so that the else gets associated with a) inner most if statement b) outer most if statement

You might also like