In this tutorial you will learn about the C Program to find Smallest of Three Numbers and its application with practical example.
C Program to find Smallest of Three Numbers
In this tutorial, we will learn to create a C program that will find the Smallest of Three Numbers using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Conditional statement in C programming.
Program to find the Smallest of Three Numbers
In c programming, it is possible to take numerical input from the user and find the Smallest of Three Numbers with the help of a very small amount of code. The C language has many types of header libraries which has supported function in them with the help of these files the programming is easy. But today we will find the Smallest of Three Numbers using c programming.
Algorithm:-
With the help of this program, we can find the Smallest of Three Numbers.
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables for the program. 2. Taking the input numbers. 3. Checking the smallest number. 4. Printing the smallest number. 5. End the program. |
Program to find the Smallest of Three Numbers:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#include<stdio.h> int main() { //declaring variables int no1,no2,no3; //taking first integer number from the user. printf("Enter first integer number:"); //Scanning the input integer scanf("%d",&no1); //taking second integer number from the user. printf("Enter second integer number:"); //Scanning the input integer scanf("%d",&no2); //taking third integer number from the user. printf("Enter third integer number:"); //Scanning the input integer scanf("%d",&no3); //calculating the smallest of three number if(no1 < no2 && no1 < no3) { //printing the smallest of three number printf("%d is smallest",no1); } else if(no2 < no3) { //printing the smallest of three number printf("%d is smallest",no2); } else { //printing the smallest of three number printf("%d is smallest",no3); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- no1 = it will hold the integer value.
- no2 = it will hold the integer value.
- no3 = it will hold the integer value.
Input numbers for the program.
Program Logic Code.
Printing output for smallest number.