C Program to find Smallest number among three

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

Interview Questions Categories

C Programming Interview Preparation

Core Java Programming Interview Preparation

Python Programming Interview Preparation