C Program To Find The Smallest of 2 Numbers Using if else
Algorithm -:
Program Start
Declare Variables
Input Two numbers
Check the condition
Display answer according the condition
Program End
Program -:
//C program to find Smallest of two numbers Using If Else
#include<stdio.h>
int main()
{
// Variable declaration
int a,b, small;
printf("Enter Two Numbers\n");
scanf("%d %d",&a,&b);
// Small among a and b
if(a<b)
{
small = a;
}
else
{
small = b;
}
//Display smallest number
printf("%d is smallest number",small);
return 0;
}
Output -:
Enter Two Numbers
10
29
10 is smllest number
C Program To Find The Smallest of 3 Numbers Using if else
Algorithm -:
Program Start
Declare Variables
Input three number From User
Check the condition
Display answer according the condition
Program End
Program -:
//C program to find Smallest among three numbers Using if else
#include<stdio.h>
void main()
{
// Variable declaration
int a,b,c, small;
printf("Enter Three Number\n");
scanf("%d %d %d",&a,&b,&c);
// Small among a, b and c
if(a<b)
{
if(a<c)
small = a;
else
small = c;
}
else
{
if(b<c)
small = b;
else
small = c;
}
//Display smallest number
printf("%d is smallest number",small);
return 0;
}
Output -:
Enter Two Numbers
10
29
10 is smllest number
C Program To Find The Smallest of 4 Numbers Using if else
Program -:
//C program to find Smallest of four numbers Using If Else
#include<stdio.h>
int main()
{
// Variable declaration
int a,b,c,d, small;
printf("Enter four Numbers\n");
scanf("%d %d %d %d",&a,&b,&c,&d);
// Small among a, b, c and d
if(a<b)
{ if(a<c)
{
if(a<d)
{
small = a;
}
else
{
small = d;
}
}
else
{ if(c<d)
small = c;
else
small = d;
}
}
else
{ if(b<c)
{
if(b<d)
{
small = b;
}
else
{
small = d;
}
}
else
{ if(c<d)
{
small = c;
}
else
{
small = d;
}
}
}
//Display smallest number
printf("%d is Smallest Number",small);
return 0;
}
Output -:
Enter Four Numbers
10
28
19
7
7 is smallest number
C Program To Find The Smallest of 5 Numbers Using if else
Program -:
//C program to find Smallest of five numbers Using If Else
#include<stdio.h>
int main()
{
// Variable declaration
int a,b,c,d,e, small;
printf("Enter five Numbers\n");
scanf("%d %d %d %d %d",&a,&b,&c,&d, &e);
// Small among a, b, c, d and e
if(a<b)
{ if(a<c)
{
if(a<d)
{
if(a<e)
small = a;
else
small = e;
}
else
{
if(d<e)
small = d;
else
small = e;
}
}
else
{ if(c<d)
{
if(c<e)
small = c;
else
small = e;
}
else
{
if(d<e)
small = d;
else
small = e;
}
}
}
else
{ if(b<c)
{
if(b<d)
{ if(b<e)
small = b;
else
small = e;
}
else
{ if(d<e)
small = d;
else
small = e;
}
}
else
{ if(c<d)
{ if(c<e)
small = c;
else
small = e;
}
else
{ if(d<e)
small = d;
else
small = e;
}
}
}
//Display smallest number
printf("%d is Smallest Number",small);
return 0;
}
Output -:
Enter five numbers
19
29
18
27
13
13 is smallest number
C Program To Find The Smallest of 2 Numbers Using if else
Algorithm -:
Program -:
Output -:
C Program To Find The Smallest of 3 Numbers Using if else
Algorithm -:
Program -:
Output -:
C Program To Find The Smallest of 4 Numbers Using if else
Program -:
Output -:
C Program To Find The Smallest of 5 Numbers Using if else
Program -:
Output -:
need an explanation for this answer? contact us directly to get an explanation for this answer