This C++ Program demonstrates the use of comparison operators. Here two numbers are given as input and the result of operation is output on the screen.
Here is source code of the C++ program which demonstrates the use of comparison operators. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ program to demonstrate use of comparison operators
*/
#include<iostream>
using namespace std;
int main()
{
int Num1, Num2;
cout << "Enter two numbers to be operated with comparison operators: ";
cin >> Num1 >> Num2;
cout << endl;
cout << "Num1 > Num2 = " << ((Num1 > Num2) ? "True" : "False") << endl;
cout << "Num1 < Num2 = " << ((Num1 < Num2) ? "True" : "False") << endl;
cout << "Num1 >= Num2 = " << ((Num1 >= Num2) ? "True" : "False") << endl;
cout << "Num1 <= Num2 = " << ((Num1 <= Num2) ? "True" : "False") << endl;
cout << "Num1 == Num2 = " << ((Num1 == Num2) ? "True" : "False") << endl;
cout << "Num1 != Num2 = " << ((Num1 != Num2) ? "True" : "False") << endl;
return 0;
}
$ g++ main.cpp $ ./a.out Enter two numbers to be operated with comparison operators: 1 10 Num1 > Num2 = False Num1 < Num2 = True Num1 >= Num2 = False Num1 <= Num2 = True Num1 == Num2 = False Num1 != Num2 = True $ ./a.out Enter two numbers to be operated with comparison operators: 5 5 Num1 > Num2 = False Num1 < Num2 = False Num1 >= Num2 = True Num1 <= Num2 = True Num1 == Num2 = True Num1 != Num2 = False
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Related Posts:
- Apply for C++ Internship
- Practice Programming MCQs
- Check Computer Science Books
- Apply for Computer Science Internship
- Check Programming Books