C

# C program to find smallest number among thre three number

## Learn how to find the smallest number of the three number in C language using if statement:

In this article, you’ll learn to find the smallest number of the three number in details with example and explanation in C language without giving input from the keyboard or giving input from the keyboard.

### Q: What is the purpose of this program

Ans: We create a program in C language that helps us to find among smallest three number without giving input from the keyboard or giving input from the keyboard.

There are many processes to find the smallest among the three number some are below given:

• Using if statement
• Using if…else statement
• Using Nested if…else statement

Here, we find the smallest number of the three number by using if statement.

#### Explanation:

• First, create three variable here we create num1, num2, num3 for storing three number then
• Check num1 with num2 and num1 with num3
• If num1 is smaller than num2 and num3, then print on the screen the value of num1 and check the next statement.
• Check num2 with num3 and num2 with num1
• If num2 is smaller than num3 and num1, then print on the screen the value of num2 and check the next statement.
• Check num3 with num1 and num3 with num2
• If num3 is smaller than num1 and num2, then print on the screen the value of num3 and stop checking and print on the screen which is the smallest among three number.

Q: Write a program in C language to find smallest among three number

Solution:

 #include #include int main() { int num1=45,num2=41,num3=49; if(num1<=num2 && num1<=num3) { printf(“smallest number is %d “,num1 ); } if(num2<=num3 && num2<=num1) { printf(“smallest number is %d “,num2 ); } if(num3<=num1 && num3<=num2) { printf(“smallest number is %d “,num3 ); } getch(); }

 The output of this program: smallest number is 41

Q: Write a program in C language to find smallest among three number, input is given by user

Solution:

 #include #include int main() { int num1,num2,num3; printf(“Enter three number: “); scanf(“%d %d %d”, &num1, &num2, &num3); if(num1<=num2 && num1<=num3) { printf(“smallest number is %d “,num1 ); } if(num2<=num3 && num2<=num1) { printf(“smallest number is %d “,num2 ); } if(num3<=num1 && num3<=num2) { printf(“smallest number is %d “,num3 ); } getch(); }

 The output of this program: Enter three number: 56 54 59 smallest number is 54

Note: In the above two program supports only integer value if enter a real value like 2.2, 4.5, 8.6 then it will not show the result. To show the result we declare the variable with a float in place of int. Examples are given below:

Q: Write a program in C language to find smallest among three number

Solution:

 #include #include int main() { float num1=41.90,num2=41.14,num3=41.56; if(num1<=num2 && num1<=num3) { printf(“smallest number is %.2f “,num1 ); } if(num2<=num3 && num2<=num1) { printf(“smallest number is %.2f “,num2 ); } if(num3<=num1 && num3<=num2) { printf(“smallest number is %.2f “,num3 ); } getch(); }

 The Output of this program: smallest number is 41.14

Q: Write a program in C language to find smallest among three number, input is given by user

Solution:

 #include #include int main() { float num1,num2,num3; printf(“Enter three number: “); scanf(“%f %f %f”, &num1, &num2, &num3); if(num1<=num2 && num1<=num3) { printf(“smallest number is %.3f “,num1 ); } if(num2<=num3 && num2<=num1) { printf(“smallest number is %.3f”,num2 ); } if(num3<=num1 && num3<=num2) { printf(“smallest number is %.3f “,num3 ); } getch(); }
 The output of this program: Enter three number: 55.235 55.258 55.894 smallest number is 55.235