Thursday, February 1, 2024

C Language - Conditional Control Statements - If Conditions - Find out the highest number from three given numbers.

Control Statements (Conditional Control Statements)
If Conditions

Example 2: Find out the highest number from three given numbers.

#include <stdio.h>

#include <conio.h>

void main()

{

            int a,b,c,h;

            clrscr();

            printf("\nENTER THREE NUMBERS:\n");

            scanf("%d %d %d",&a,&b,&c);

            h=a;

            if(b>h)

                        h=b;

            if(c>h)

                        h=c;

            printf("\nHIGHEST NUMBER IS %d",h);

            getch();

}

 

Alternative Method

 

#include <stdio.h>

#include <conio.h>

void main()

{

            int a,b,c;

            clrscr();

            printf("\nENTER THREE NUMBERS:\n");

            scanf("%d %d %d",&a,&b,&c);

            if(a>b && a>c)

                        printf("\nHIGHEST NUMBER IS %d",a);

            if(b>c && b>a)

                        printf("\nHIGHEST NUMBER IS %d",b);

            if(c>a && c>b)

                        printf("\nHIGHEST NUMBER IS %d",c);

            getch();

}

 

No comments: