Lab # 3

© Manzur Ashraf

 

Objective:

Learn the selection structures.

 

Scope:

The student should know the following:

       1.         One-Way if

if (guess==magic) printf("Right");

      2.         Two-Way if

if (expression) {

statement1;

}

else {

statement 2;

}

     

OR,  expression? stmt1:stmt2

example:  x=10;

y= x>9 ? 100 : 200;

      3.         Nested if

 

if (exp1) stmt1;

else if (expr2) stmt2;

else if (expr3) stmt3;

else stmt4;

 

      4.         Switch

 swith(var){

case constant1: stmt sequence

break;

case constant2: stmt sequence

break;

 

case constant3: stmt sequence

break;

.

.

default: stmt sequence

}

 

Discussion:

The following problem will be discussed:

  1. Write a program to find the roots of a quadratic equation. Consider the case of imaginary roots.


Exercises:

  1. Write a program that reads three integer numbers and prints the highest among them.

 

  1. Write a program that prompts the user for the day number (0 to 6) and prints the day name (Saturday to Friday) using the switch statement.

 

Evaluation:

Your grade will depend on your active participation and seriousness during the lab.