All articles
c

A program to find largest among three numbers

Share this article

Share on LinkedIn Share on X (formerly Twitter)

C Programming Language 019

The following code shows how to write a program to explain NESTED IF. To find the largest among three numbers.

Program

#include <stdio.h>
 
void main()
{
    int a, b, c;
    printf("Enter three no.s:");
    scanf("%d %d %d", &a, &b, &c);
 
    if (a > b)
        if (a > c)
            printf("Max. = %d", a);
        else
            printf("Max. = %d", c);
    else if (b > c)
        printf("Max. = %d", b);
    else
        printf("Max. = %d", c);
 
    printf("\n");
}

Result

Enter three no.s:7 40 58
Max. = 58

Comments