Search Here

C program to find largest number among three using Logical Operators and nested if...else



/* C program to find the Largest Number using logical AND operator */

void main()
{
    int a,b,c;
    
    printf("Enter three integer numbers to find the biggest one: ");
    scanf("%d%d%d",&a,&b,&c);
    if(a!=b && a!=c && b!=c)
    {
        if(a>b && a>c)
           printf("\nMax=%d",a);
        else if(b>a && b>c)
            printf("\nMax=%d",b);
        else
            printf("\nMax=%d",c);
    }
    else
        printf("\nGiven numbers are equal");
}


/* Find the biggest number using nested... if */

void main()
{
    int a,b,c;
    printf("Enter three numbers to find the biggest one");
    scanf("%d%d%d",&a,&b,&c);
    if(a>b)
    {
        if(a>c)
        {
            printf("\nMax=%d",a);
        }
    }
    else if(b>a)
    {
        if(b>c)
        {
            printf("\nMax=%d",b);
        }
    }
    else
    {
        printf("\nMax=%d",c);
    }
}


Output

No comments:

Post a Comment