Find elements

C Program to display smallest among three numbers

C Program to display smallest  among three numbers

In this tutorial, we discuss C Program to display smallest  among three numbers

In this program, we will discuss a simple concept of the program to find the smallest number among three numbers in the C programming language.

In this topic, we learn how to find the smallest number from given three numbers using if statements.

Program to find the smallest among three numbers

Find smallest among integer numbers

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1,num2,num3;//variable declaration
    printf("Enter tree numbers\n");
    scanf("%d %d %d",&num1,&num2,&num3);
    //Takse three input num1,num2,num3 from user
    if(num1<num2 && num1<num3){
            //check whether num1 is smaller than num2 and num3
        printf("\n%d is smallest",num1);
    }//if it is truen this statement is displayed
    else if(num2<num3){
        //when it is false then check num2 or num 3 small
        printf("\n%d is smallest",num2);//when it is true this statements is displayed
    }
    else{
        printf("\n%d is smallest",num3);
    }//all statements are false this statement is displayed
    getch();
    return 0;
}

When the above code is compiled and executed, it produces the following results

Enter three numbers
76
54
32

32 is smallest

 

Find smallest among float numbers

#include <stdio.h>
#include <stdlib.h>

int main()
{
    float num1,num2,num3;//variable declaration
    printf("Enter three numbers\n");
    scanf("%f %f %f",&num1,&num2,&num3);
    //Takse three input num1,num2,num3 from user
    if(num1<num2 && num1<num3){
            //check whether num1 is smaller than num2 and num3
        printf("\n%.2f is smallest",num1);
    }//if it is truen this statement is displayed
    else if(num2<num3){
        //when it is false then check num2 or num 3 small
        printf("\n%.2f is smallest",num2);//when it is true this statements is displayed
    }
    else{
        printf("\n%.2f is smallest",num3);
    }//all statements are false this statement is displayed
    getch();
    return 0;
}

When the above code is compiled and executed, it produces the following results

Enter three numbers
34.56
23.43
67.54

23.43 is smallest

 

Suggested for you

Operator in C language

If statements in C language

Variables in C language

 

Java Program to smallest and largest among three numbers
C Program to largest and smallest among three numbers
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago