C Program To Find The Largest Number Using if else

In this article, we are going to write C Program To Find The Largest Number Using if else

We will make this program in the following way -:

  • C Program To Find The Largest of 2 Numbers Using If Else
  • C Program To Find The Largest of 3 Numbers Using If Else
  • C Program To Find The Largest of 4 Numbers Using If Else
  • C Program To Find The Largest of 5 Numbers Using If Else

To make this program, we will use the following concept given below.

If you do not know about these topics well, then you may not understand this program, so you should know about them in detail from the link given above.

Now without wasting time let’s start programming.

C Program To Find The Largest Number Using if else

C Program To Find The Largest of 2 Numbers Using if else

Algorithm -:

  1. Program Start
  2. Variable Declaration
  3. Input two number
  4. Check the condition, ternary (conditional) operator.
  5. Display answer according the condition
  6. Program End

Program -:

//C program to find Largest among two numbers using if else

#include<stdio.h>
void main()
{
  // Variable declaration
   int a,b,larg;

   printf("Enter two number\n");
   scanf("%d %d",&a,&b);

  // Smallest among a and b
   if(a>b)
      larg = a;
   else
      larg = b;

  //Display largest number
   printf("largest among 2 Number is : %d",larg);

}

Output -:

Enter two numbers
10
8

Largest among 2 number is : 10

C Program To Find The Largest of 3 Numbers Using if else

Program -:

//C program to find Largest among three numbers Using if else

#include<stdio.h>
void main()
{
  // Variable declaration
   int a,b,c, larg;

   printf("Enter Three Number\n");
   scanf("%d %d %d",&a,&b,&c);

  // larg among a, b and c
  if(a>b)
  {
      if(a>c)
        larg = a;
      else
        larg = c;
  }
  else
  {
      if(b>c)
        larg = b;
      else
        larg = c;
  }

//Display Largest Number
 printf("%d is largest number",larg);

return 0;
}

Output -:

Enter Three Numbers
9
15
19

19 is largest number

C Program To Find The Largest of 4 Numbers Using if else

Program -:

//C program to find Largest of four numbers Using If Else

#include<stdio.h>
int main()
{
  // Variable declaration
   int a,b,c,d, larg;

   //input numbers
   printf("Enter four Numbers\n");
   scanf("%d %d %d %d",&a,&b,&c,&d);

  // larg among a, b, c and d
    if(a>b)
      {  if(a>c)
          {
              if(a>d)
              {
                  larg = a;
              }
              else
              {
                  larg = d;
              }
          }
          else
          {  if(c>d)
              larg = c;
             else
              larg = d;
          }
      }
    else
      { if(b>c)
           {
               if(b>d)
               {
                larg = b;
               }
               else
               {
                larg = d;
               }
           }
           else
           { if(c>d)
               {
                larg = c;
               }18
              else
              {
                larg = d;
              }
           }

      }

  //Display Largest number
    printf("%d is Largest Number",larg);

    return 0;
}

Output -:

Enter four Numbers
10
28
129
18

129 is Largest Number

C Program To Find The Largest of 5 Numbers Using if else

Program -:

//C program to find Largest of five numbers Using If Else

#include<stdio.h>
int main()
{
  // Variable declaration
   int a,b,c,d,e, larg;

   printf("Enter five Numbers\n");
   scanf("%d %d %d %d %d",&a,&b,&c,&d, &e);

  // larg among a, b, c, d and e
    if(a>b)
      {  if(a>c)
          {
              if(a>d)
              {
                if(a>e)
                  larg = a;
                else
                  larg = e;
              }
              else
              {
                  if(d>e)
                    larg = d;
                   else
                    larg = e;
              }

          }
          else
          {  if(c>d)
               {
                    if(c>e)
                        larg = c;
                    else
                        larg = e;
               }
             else
             {
                 if(d>e)
                    larg = d;
                 else
                    larg = e;
             }

            }
      }
    else
      { if(b>c)
           {
               if(b>d)
               { if(b>e)
                   larg = b;
                 else
                    larg = e;
               }
               else
               { if(d>e)
                   larg = d;
                 else
                    larg = e;
               }
           }
           else
           { if(c>d)
               { if(c>e)
                   larg = c;
                 else
                   larg = e;
               }
              else
              { if(d>e)
                   larg = d;
                else
                   larg = e;
              }
           }
      }

  //Display Largest number
    printf("%d is Largest Number",larg);

    return 0;
}

Output -:

Enter five numbers
18
32
28
281
828

828 is Largest Number

Conclusion

In this article, we have created all the following programs -:

  • C Program To Find The Largest of 2 Numbers Using If Else
  • C Program To Find The Largest of 3 Numbers Using If Else
  • C Program To Find The Largest of 4 Numbers Using If Else
  • C Program To Find The Largest of 5 Numbers Using If Else

If you have difficulty to understanding any program or have any doubts or questions, then tell me in the comment below.

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging

Leave a Comment