Write a C Program to Find the Smallest Number among Three Numbers (integer values) using Nested IF-ELSE statement
Write a C Program to Find the Smallest Number among Three Numbers (integer values) using Nested IF-ELSE statement, the code for find the smallest number among three numbers, How to find the smallest number using if-else.
If you don't know how to implement if else statement in c you can check out this post here
Here we have taken 3 input n1, n2, n3 by using scanf statement. Then we compare the numbers inside the condition box of if statement. We have also use a logical and operator i.e &&.
Here the condition " (n1<n2&&n1<n3) " it means (n1<n3 and n1<n3 ) i.e both the condition must true to execute the body of the if statement.
you may also like to read:
- How To Print Name in C Language
- How To Download C Compiler Free And How To Compile And Run A Program from Mobile Or PC
- Introduction To C Language (c programming basics)
Here is the code to Find the Smallest Number among Three Numbers (integer values) using Nested IF-ELSE statement
#include <stdio.h>
int main()
{
int n1, n2, n3;
scanf("%d %d %d", &n1, &n2, &n3);
if(n1<n2&&n1<n3)
printf("%d is the smallest number.", n1);
else if(n2<n1&&n2<n3)
printf("%d is the smallest number.", n2);
else
printf("%d is the smallest number.", n3);
}
Input Output
100 200 400 | 100 is the smallest number. |
Related post:
- Write a C program to check if a given Number is zero or Positive or Negative Using if...else statement.
- Write a C Program to calculates the area (floating point number with two decimal places) of a Circle given it’s radius (integer value).
0 Comments