Dremendo Tag Line

Input numbers and print the smallest in C

if else if - Question 7

In this question, we will see how to input 3 unique integers and print the smallest among them in C programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.

Q7) Write a program in C to input 3 unique integers and print the smallest among them. Make use of logical operator && to solve this question.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int a,b,c;
    printf("Enter 3 unique numbers\n");
    scanf("%d%d%d",&a,&b,&c);
    if(a==b || b==c || c==a)
    {
        printf("Please enter 3 unique numbers");
    }
    else if(a<b && a<c)
    {
        printf("Smallest number is %d",a);
    }
    else if(b<a && b<c)
    {
        printf("Smallest number is %d",b);
    }
    else
    {
        printf("Smallest number is %d",c);
    }
    return 0;
}

Output

Enter 3 unique numbers
78
34
9
Smallest number is 9
video-poster