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 -:
- 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 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 (Simple Way)
Algorithm -:
- Program Start
- Declaration of Variables
- Input Two number
- Check the condition
- Display answer according the condition
- 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 -:
- Program Start
- Declaration of Variables
- Input Two number
- Calling Function to find Largest Number
- Check the condition
- Display answer according the condition
- 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
Read More
- Download C Language Notes Pdf
- C Language Tutorial For Beginners
- C Programming Examples With Output
- 250+ C Programs for Practice PDF Free Download
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.