Find the Greatest of Two Numbers in C


In this example, the user is asked to enter two numbers as an input. The program will then find the greatest number by comparing two numbers with each other and display the results.

#include <stdio.h>

int main()
    double num1, num2;
    printf("Please enter the first number: ");
    scanf("%lf", &num1);
    printf("Please enter the second number: ");
    scanf("%lf", &num2);
    if(num1 > num2) {
        printf("First number is the largest number.\n");      

    else {
        printf("Second number is the largest number.\n");      
    return 0;

First, two double variables are declared, namely num1 and num2. Next, the user is asked to enter the first and second number which will be stored in num1 and num2 respectively. The if-else statement compares the first number with the second number. Finally, the greatest number is displayed on the console.


Please enter the first number: 54
Please enter the second number: 23
First number is the largest number.


Please enter your comment!
Please enter your name here