All articles
c

A program to find maximum of two numbers using IF ELSE

Share this article

Share on LinkedIn Share on X (formerly Twitter)

C Programming Language 017

The following code shows how to write a program to explain IF ELSE. To find maximum of two numbers.

Program

#include <stdio.h>
 
void main()
{
    int a, b;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
 
    if (a > b)
    {
        printf("Maximum = %d", a);
    }
    else
    {
        printf("Maximum = %d", b);
    }
 
    printf("\n");
}

Result

Enter two numbers: 40 35
Maximum = 40

Comments