1 / 7

Today’s Agenda

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.

calum
Download Presentation

Today’s Agenda

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Today’s Agenda • Examples on if statement • Switch case statement • Repetition Control Structure • for statement • while statement • do-while statement

  2. 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.

  3. 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.

  4. 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.

  5. Write a program to implement the following decision table to characterize an earth quake based on its Richter scale number.

  6. 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

  7. 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”); • }

More Related