70 likes | 162 Views
Today’s Agenda. Examples on if statement Switch case statement Repetition Control Structure for statement while statement do-while statement. Exercise: on if-else. Write a program to determine whether a number is odd or even and print the appropriate message.
E N D
Today’s Agenda • Examples on if statement • Switch case statement • Repetition Control Structure • for statement • while statement • do-while statement
Exercise: on if-else • Write a program to determine whether a number is odd or even and print the appropriate message. • Write a program to find the smallest of the three numbers. • Write a program to determine whether the inputted year is a leap year or not.
Write a program to reverse a three digit decimal number and determine whether the two numbers are equal or not. • Write a program to add the digits of a number. Let the number 4 digit only. • Write a program to convert a decimal number ranging from 1 to 7 into binary.
Exercise: on if-else • Write a program to calculate area of a circular ring. • Write a program that takes the x-ycoordinates of a point in the Cartesian plane and prints a message telling either an axis on which the point lies or the quadrant in which it is found.
Write a program to implement the following decision table to characterize an earth quake based on its Richter scale number.
Switch evaluateexpression = const1? • switch (expression) • {case const1: block-1; break;case const2: block-2; break;default: block-3; • } • next_statement block-1 T F = const2? block-2 T F block-3
Switch Example • /* same as month example for if-else */ • switch (month) { case 4: case 6: case 9: case 11: printf(“Month has 30 days.\n”);break; case 1: case 3: case 5: • case 7: • case 8: • case 10: • case 12: • printf(“Month has 31 days.\n”);break; • case 2: printf(“Month has 28 or 29 days.\n”);break; default: printf(“Don’t know that month.\n”); • }