Write a C Program to find the Greatest number



Sumit Kar, Timus Rak, Greatest of, Two, Three, Numbers, C Program




/*Find the Greatest of Two Numbers*/




#include<stdio.h>

void main()

{

    int a,b;

    printf("Enter value of A: ");

    scanf("%d",&a);

    printf("Enter value of B: ");

    scanf("%d",&b);


    if(a>b)


        printf("A is larger");

    else if(b>a)

        printf("B is larger");

    else

        printf("A and B are equal");

}





/*    Find Greatest value between two variables - using  Conditional Operator  */





#include<stdio.h>


void main()

{

 int a,b,d;


 printf("Type values of A and B : ");


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

 d=(a>=b?a:b);

 printf("Greatest value : %d",d);

}







/*Find the Greatest of Three Numbers*/





#include<stdio.h>


void main()

{

    int a,b,c;

    printf("Enter value of A: ");

    scanf("%d",&a);

    printf("Enter value of B: ");

    scanf("%d",&b);

    printf("Enter value of C: ");

    scanf("%d",&c);


    if(a >= b && a >= c)


        printf("%d is largest",a);

    else if(b >= a && b >= c)

        printf("%d is largest",b);

    else if(c >= a && c >= b)

        printf("%d is largest",c);


}










/* Find Greatest among 3 variables using nested if */







#include <stdio.h>


void main()


{


    int a,b,c;


    printf("Enter 3 numbers: \n");


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


    if(a>=b)


    {


        if(a>=c)


            printf("%d is Greatest",a);


        else


            printf("%d is Greatest",c);


    }


    else if(b>=c)


        printf("%d is Greatest",b);


    else


        printf("%d is Greatest",c);


}















/*    Find greatest value among three variable using conditional operator    */







#include<stdio.h>


void main()


{


 int a,b,c,d;



 printf("Type values of A,B and C : ");


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


 d=(a>=b?a>=c?a:c:b>=c?b:c);


 printf("Greatest value : %d",d);


}



0 Comments