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

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:

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);
}

c programing langauage


          Input                                                Output
100 200 400
 100 is the smallest number.

 Related post:



Post a Comment

0 Comments