Wednesday, 10 September 2014

Find Greatest of three Numbers in C Language with Example

C Language Program to Find the greatest of three Numbers. This sample  simple program discuss about finding largest value from the given few numbers by the C source code. It is a simple source program to understand easily. It can be used in all LAB exams and theory exams also. It is an useful C Language program for beginners.

GREATEST OF THREE NUMBERS IN C


Greatest of three numbers in C is used find the biggest of 3 numbers in an entered value by using conditional statement (nested if… else if). First check the outer if statement, condition is correct go for inner if…else if statement, else it will go to else if statement or otherwise check inner if. If it is true it will give the present value or else were.

//Header files
#include<stdio.h>
#include<conio.h>a
void main()
{
 
//Program variables
float value1,value2,value3;
 
    clrscr();//Function is used to clear the previous output
 
printf("\n\n FIND GREATEST OF THREE NUMBERS"); //display function
    printf("\n\n ENTER THE THREE VALUES TO COMPARE\t");
    scanf("%f%f%f",&value1,&value2,&value3); //getting value function
 
if(value1>value2) //Nested if…else statement(conditional statement)
    {
        if(value1>value3)
        {
            printf("Greatest Number Is %f",value1);
        }
        else if(value3>value2)
        {
            printf("Greatest Number Is %f",value3);
        }
    }
    else if(value2>value3)
    {
        printf("Greatest Number Is %f",value2);
    }
    else if(value3>value1)
    {
        printf("Greatest Number Is %f",value3);
    }
    getch();
}


   

No comments:

Post a Comment

Note: only a member of this blog may post a comment.