In this tutorial, we are going to learn the writing program in C to find the smallest number among 3 given integers.
So here our problem statement is, we have given 3 integers and we have to find the smallest number among three.
For Example
We Will Give 3 integers like 4,1,9. Here we will get output 1 because 1 is the smallest among three.
How our program will behave?
- Program will take 3 integers as an input and it will return 1 integer as an output which will be smallest/minimum.
- We are using if else statement to compare the elements.
- Our logic is like we will pick one element and compare it with the rest two. If picked integer is smallest then we will print that picked number as smallest number. If not then we will pick another number and compare it with others two.
C Program to find Smallest number among three
#include<stdio.h>
void main() {
int a, b, c;
printf("Enter the value of a: ");
scanf("%d", & a);
printf("Enter the value of b: ");
scanf("%d", & b);
printf("Enter the value of c: ");
scanf("%d", & c);
if (a <= b && a <= c)
printf("a = %d is smallest", a);
if (b <= a && b <= c)
printf("b = %d is smallest", b);
if (c <= a && c <= b)
printf("c = %d is smallest", c);
}
Output 1:
Enter the value of a: 12
Enter the value of b: 55
Enter the value of c: 34
a = 12 is smallest
Output 2:
Enter the value of a: 34
Enter the value of b: 66
Enter the value of c: 74
a = 34 is smallest
[wpusb]
Also Prepare Below Important Question
- Sum of digits of Given Number in Java
- Hibernate Interview Questions for 2+ years of experience
- 68 Most Important Microservices Interview Questions
- 60 Most Important Git Interview Questions
- 50+ Mostly asked Java Interview Questions for 6 Years Exp.
- 60+ Mostly Asked Java Interview Questions for 4 Years Exp
- 60+ Mostly asked Java Interview Question for 3+ Years
- 60+ Spring Boot interview questions for 4+ years Exp.
- 60+ Mostly Asked Spring Boot Interview Questions for 3+ Yrs
- Scenario Based Java 8 Coding Interview Questions (For Experienced)
- Python Program to add two numbers without addition operator
- Mostly Asked Java Interview Questions For 2 Yrs Experience
- Find All Pairs in Array whose Sum is Equal to given number Using Java
- Java Program to find GCD of two Numbers using Recursion
- Python Program to Separate Characters in a Given String
- Python Program to add two number using Recursion
- Python Program to Find Highest Frequency Element in Array
- Python Program to Merge two Arrays
- Perform left rotation by two positions in Array Using Python
- Python Program to Delete Element at Given Index in Array
Interview Questions Categories
C Programming Interview Preparation
Core Java Programming Interview Preparation
- Core Java Programming Coding Questions
- Core Java Pattern Programming Questions
- Core Java Programming Interview Questions