- On
- By
- 0 Comment
- Categories: category, Find elements
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 the largest and smallest number Using if statements
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
Suggested for you