category

Cpp program to biggest and smallest of three numbers

Cpp program to biggest and smallest of three numbers

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

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

find largest and smallest among three numbers

Cpp program to biggest and smallest of three numbers

Find among integer numbers

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int num1,num2,num3;  //declare the variables

    cout << "Enter the first number: ";
    cin>>num1;//get input from user for num1
    cout << "Enter the second number: ";
    cin>>num2;//get input from user for num2
    cout << "Enter the third number: ";
    cin>>num3;//get input from user for num3

    cout<<"\n\nThe biggest number is: ";
    if((num1>num2)&&(num1>num3)){
        cout<<num1;
    }
    else if(num2>num3){
       cout<<num2;
    }
    else{
        cout<<num3;
    }

    cout<<"\n\nThe smallest number is: ";
    if((num1<num2)&&(num1<num3)){
        cout<<num1;
    }
    else if(num2<num3){
        cout<<num2;
    }
    else{
        cout<<num3;
    }

    getch();
    return 0;
}

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

Enter the first number: 34
Enter the second number: 12
Enter the third number: 67

The biggest number is: 67

The smallest number is: 12

 

Find among float numbers

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    float num1,num2,num3;  //declare the variables

    cout << "Enter the first number: ";
    cin>>num1;//get input from user for num1
    cout << "Enter the second number: ";
    cin>>num2;//get input from user for num2
    cout << "Enter the third number: ";
    cin>>num3;//get input from user for num3

    cout<<"\n\nThe biggest number is";
    if((num1>num2)&&(num1>num3)){
        cout<<num1;
    }
    else if(num2>num3){
       cout<<num2;
    }
    else{
        cout<<num3;
    }

    cout<<"\n\nThe smallest number is";
    if((num1<num2)&&(num1<num3)){
        cout<<num1;
    }
    else if(num2<num3){
        cout<<num2;
    }
    else{
        cout<<num3;
    }

    getch();
    return 0;
}


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

Enter the first number: 34.75
Enter the second number:76.34
Enter the third number:87.67

The biggest number is 87.67
The smallest number is 34.76

Similar post

C code to smallest among three numbers

C++ code to smallest among three numbers

Python code to smallest among three numbers

 

Java code to find smallest of three numbers using method

C code to smallest among three numbers using function

C++ code to smallest among three numbers using function

Python code to smallest among three numbers using function

 

Java code to find smallest of three numbers using ternary operator

C code to smallest among three numbers using ternary operator

C++ code to smallest among three numbers using ternary operator

 

Suggested for you

Addition of two numbers in Java

Addition of two numbers in C

Addition of two numbers in C++

Addition of two numbers in Python

Addition of two numbers in C#

Addition of two numbers in PHP

Addition of two numbers in JavaScript

 

Sum of two numbers in Java using method

Sum of two numbers in C++ using function

Sum of two numbers in Python using function

 

C program to add two numbers without using arithmetic operators

C++ program to add two numbers without using arithmetic operators

Python program to add two numbers without using arithmetic operators

 

For loop in C++ language

While loop in C++language

The function in C++ language

 

Operator in C language

Function in C language

Data type in C language

Operator in C++ language

Data types  in C++ language

 

Single dimension Array in C++ language

If statements in C++

Data type in C++ programming language

Cpp program to display smallest number of an Array
Cpp Program to display 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…

18 hours 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