C Program to Find the Smallest of Three Numbers

C Program to Find the Smallest of Three Numbers

In this article, we are going to write a simple C program, in which, we are given three numbers, and we need to find the smallest of the given three numbers. This program is very simple to do, provided that you just know the simple logic behind the program, which we will discuss in this quick article.

C Program to Find the Smallest of Three Numbers

When you have three numbers given, and you need to check the smallest of them, you can just make use of the if-else statements. In the below video, you can find a detailed explanation and the program for finding the smallest of three given numbers. After watching the video, you can also perform this simple program, and get the smallest of three numbers.

Here is the C program to find the smallest of three numbers –

#include <stdio.h>

int main() {
int num1, num2, num3;
printf(“Please Enter the three numbers:”);
scanf(“%d”, &num1);
scanf(“%d”, &num2);
scanf(“%d”, &num3);

if ((num1 < num2) && (num1 < num3))
printf(“%d is the smallest numbern”, num1);
else if (num2 < num3)
printf(“%d is the smallest numbern”, num2);
else
printf(“%d is the smallest numbern”, num3);
return 0;
}

Program Output 1 –
Please Enter the three numbers:6 16 19
6 is the smallest number

Program Output 2 –
Please Enter the three numbers:25 4 31
4 is the smallest number

Program Output 3 –
Please Enter the three numbers:14 4 1
1 is the smallest number