Comparison of Numbers using C++ Programming Language

Comparison of Numbers:

It means it takes two numbers , after comparing them will tell which number is greater or not.The different signs are used to compare two thins.Greater than , smaller than or in case of equal value equal sign.

Explanation of Program Code:

For input and output streams, include library file iostream or iostream.h for older version. Cout and cin are output and input streams respectively.Then add main function in program code which is the necessary function of every C++ program.Also include the return statement which means that there is no more statements to execute or for compiling.
So how many variables to define and about their data type, as comparison is always between the two things so definitely two variables and their data types depends upon the numbers , if they are integers then integer type and if they are decimal numbers then float or double.

Recommended Article: Read this article for better understanding of program code

Program Code:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int num1, num2 ;
cout<<  " Enter ist number   =  ";
cin>>num1;
cout<<endl;
cout<<  " Enter 2nd number   =  ";
cin>>num2;
cout<<endl;

if(num1>num2)
cout<<num1<< " is greater than "<<num2;
if(num1==num2)
cout<<"both are equal";
else
cout<<num2<<" is greater than "<< num1;
return 0;
}
Output:
Enter ist number
22
Enter 2nd number
25
25 is greater than 22
...................................................................................................................................................................

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.