C Program To Find The Largest of 2 Numbers Using if else
Algorithm -:
Program Start
Variable Declaration
Input two number
Check the condition, ternary (conditional) operator.
Display answer according the condition
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
C Program To Find The Largest of 2 Numbers Using if else
Algorithm -:
Program:-
Output -:
C Program To Find The Largest of 3 Numbers Using if else
Program -:
Output -:
C Program To Find The Largest of 4 Numbers Using if else
Program -:
Output -:
C Program To Find The Largest of 5 Numbers Using if else
Program -:
Output -:
need an explanation for this answer? contact us directly to get an explanation for this answer