NIOS Computer Science: Chapter 9 – Control Statements Part 3

Download PDF of This Page (Size: 207K)

Image of If else statement

Image of if else Statement

Image of If else statement

(2) ‘if else’ Statement

Syntax of the if- else statement

If (condition)

Statement;

else

Statement;

If Else in Flowchart

If else in Flowchart

If Else in Flowchart

Example

Write a program that will print the greatest of two numbers.

# include <iostream.h>

void main ()

{

int x, y;

cout << “Enter two numbers” <<“\n”;

cin>> x >> y ;

if ( x > y)

cout << “The bigger number is ”<< X;

else

cout << “The bigger number is” <<y;

}

Example

Write a program that will print the greatest of three numbers.

# include <iostream.h>

void main ()

{

int x, y, z, l;

cout << “Enter three numbers” <<“\n”;

cin >> x >> y>>z;

if (x > y )

l = x ;

else

l = y ;

if (l > z)

cout << “The greatest number is “ << l;

else

cout << “The greatest number is “<<z;

}

Developed by: