C program to find largest number among three numbers

devquora
devquora

Posted On: Dec 23, 2020

C program to find largest number among three numbers

 

Overview:

In this example, you'll learn to find the largest number among three numbers using if else statements. First of all, in this article I will define numbers then demonstrate the logic to find the largest number amongst three. Moreover, I will write a logic and C program to find the largest number amongst the three numbers with output. At last, I will explain the execution of this program.

Table of contents:

  1. What is number?
  2. Demonstration how to find the largest number among three numbers
  3. Logic to find the largest number among three numbers
  4. C program to find the largest number among three numbers with output
  5. Conclusion

What is a number?

Number is an object that uses digits to perform mathematical tasks. Calculus, which is a branch of mathematics, includes many numbers such as integers, whole numbers, real numbers, and imaginary numbers. Here, I will discuss numbers to perform arithmetic addition operations. Moreover, numbers are a combination of digits, some symbols and decimal points. For instance, 127.23 is a rational number. There are many numbers such as whole numbers, natural numbers(positive integer), negative integer, rational number etc.

Demonstration how to find the largest number among three numbers

Largest Number among three

Logic to find the largest number among three numbers

  • Step 1:Read the three numbers to be compared, as A, B and C.
  • Step 2:Check if A is greater than B.
  • Step 3:If true, then check if A is greater than C.
  • Step 4:If true, print 'A' as the greatest number.
  • Step 5:If false, print 'C' as the greatest number.
  • Step 6:If false, then check if B is greater than C.
  • Step 7:If true, print 'B' as the greatest number.
  • Step 8:If false, print 'C' as the greatest number.

C program to find the largest number among three numbers with output

#include  <stdio.h>
int main() 
{ 
    int A, B, C; 
  
    printf("Enter three numbers: \n"); 
    scanf("%d %d %d", &A, &B, &C); 
  
    if (A >= B) { 
        if (A >= C) 
            printf("%d is the largest number.", A); 
        else
            printf("%d is the largest number.", C); 
    } 
    else { 
        if (B >= C) 
            printf("%d is the largest number.", B); 
        else
            printf("%d is the largest number.", C); 
    } 
  
    return 0; 
} 

Output of the Program: Enter the numbers: 8 45 1 45 is the largest number.

c program quadratic equation

Conclusion:

In this program, three numbers are assigned in to the three variables one by one. Then, compare the two selected of them with the use of comparison operator. Repeat the same process for the other two. After the successful execution of the program the final largest number amongst the three are displayed on the screen.

    Related Questions

    Please Login or Register to leave a response.

    Related Articles

    C Program Examples

    C Program to convert Decimal to Binary Number

    A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

    C Program Examples

    C program to reverse a string

    This program reversed the entered string that means opposite of the previous string sequence...

    C Program Examples

    C program to reverse an Integer number

    Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..