C Program To Find Largest of Two Numbers

In this article, we are going to write a c program to find the Largest of two Numbers.

We will make this program in the following way -:

  1. C Program To Find Largest of Two Numbers Using if statement
  2. C Program To Find Largest of Two Numbers Using Function
  3. C Program To Find Largest of Two Numbers Using Conditional Operator

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 Largest of Two Numbers

C Program To Find Largest of Two Numbers (Simple Way)

Algorithm -:

  1. Program Start
  2. Declaration of Variables
  3. Input Two number
  4. Check the condition
  5. Display answer according the condition
  6. Program End

Program -:

//C Program To Find Largest of Two Numbers (Simple Way)

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

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

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

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

}

Output -:

Enter Two Numbers
39
49

Largest Number is : 45

C Program To Find Largest of Two Numbers Using Function

Algorithm -:

  1. Program Start
  2. Declaration of Variables
  3. Input Two number
  4. Calling Function to find Largest Number
  5. Check the condition
  6. Display answer according the condition
  7. Program End

Program -:

//C Program To Find Largest of Two Numbers Using Function

#include<stdio.h>
void largest(int a, int b)
{
   int larg;
  
 if(a>b)  // larg among a and b
  {
    larg = a;
  }
  else
  {
    larg = b;
  }

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

}
void main()
{
  // Variable declaration
   int a,b;

   printf("Enter Two Numbers\n");
   scanf("%d %d",&a,&b);
   largest(a,b);
}

Output -:



Enter Two Numbers
3
9

Largest Number is : 9

C Program To Find Largest of Two Numbers Using Conditional Operator

Program -:

//C Program To Find Largest of Two Numbers Using Conditional Operator

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

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

  // Larg among a, b and c
   larg = a>b?a:b;

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

}

Output -:

Enter Two Numbers
93
47

Largest Number is : 93

Conclusion

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

  • C Program To Find Largest of Two Numbers Using if statement
  • C Program To Find Largest of Two Numbers Using Function
  • C Program To Find Largest of Two Numbers Using Consitional or Ternary operator

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