C Program To Find Smallest of Three Numbers
In this article, we are going to write a c program to find Smallest of Three Numbers.
We will make this program in the following way -:
- C Program to find Smallest of Three numbers (Simple Way)
- C Program to find Smallest of Three numbers using function
- C Program to find Smallest of Three numbers using conditional operator
- C Program to find Smallest of n numbers using for loop
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 Smallest of Three Numbers Using ( Simple Way )
Algorithm -:
- Program Start
- Variable Declaration
- Input three number
- Check the condition
- Display answer according the condition
- Program End
Program -:
//C program to find Smallest among three numbers
#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("Smallest Number is : %d",small);
}
Output -:
Enter Three Numbers
12
43
28
Smallest Number is : 12
C Program To Find Smallest of Three Numbers Using Function
Algorithm -:
- Program Start
- Variable Declaration
- Input three number
- Calling Function to find Smallest Numbers among Three number
- Check the condition
- Display answer according the condition
- Program End
Program -:
//C program to find Smallest among three numbers Using Function
#include<stdio.h>
void small(int, int, int);
void main()
{
// Variable declaration
int a,b,c;
printf("Enter Three Number\n");
scanf("%d %d %d",&a,&b,&c);
//calling function to find smallest number
small(a,b,c);
}
void small(int a, int b, int c)
{ int small;
// 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("Smallest Number is : %d",small);
}
Output -:
Enter Three Number
32
23
43
Smallest Number is : 23
C Program To Find Smallest of Three Numbers Using Conditional OR Ternary Operator
Algorithm -:
- Program Start
- Variable Declaration
- Input three number
- Check the condition
- Display answer according the condition
- Program End
Program -:
//C program to find Smallest among three numbers using Conditional operator
#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
small = a<b?a<c?a:c:b<c?b:c;
//Display smallest number
printf("Smallest Among 3 Number is : %d",small);
}
Output -:
Enter Three Number
10
20
11
Smallest Number is : 10
C Program To find Smallest of n Number Using For Loop
Algorithm -:
- Program Start
- Variable Declaration
- Input number
- Check the condition
- Display answer according the condition
- Program End
Program -:
//C Program To find Smallest of n Number Using For Loop
#include<stdio.h>
void main()
{
int i,n,a[100],small;
printf("Enter How many number you want?:\n") ;
scanf("%d",&n) ;
printf("Enter %d numbers\n",n) ;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]) ;
}
small=a[0];
for(i=1;i<n;i++)
{
if(a[i]<small)
{
small=a[i];
}
}
printf("Smallest Number is : %d",small);
}
Output -:
Enter How many number you want?
5
Enter 5 number
12
134
31
23
322
Smallest Number is : 12
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 Smallest of Three numbers
- C Program to find Smallest of Three numbers using function
- C Program to find Smallest of Three numbers using conditional operator
- C Program to find Smallest of n numbers using for loop
If you have difficulty to understanding any program or have any doubts or questions, then tell me in the comment below.