This C++ Program demonstrates the use of arithmetic operators. Here 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 arithmetic 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 arithmetic operators
*/
#include<iostream>
using namespace std;
int main()
{
int Num1, Num2;
cout << "Enter two numbers to be operated with arithmetic operators: ";
cin >> Num1 >> Num2;
cout << endl;
cout << "Num1 + Num2 = " << Num1 + Num2 << endl;
cout << "Num1 * Num2 = " << Num1 * Num2 << endl;
cout << "Num1 - Num2 = " << Num1 - Num2 << endl;
if (Num2 != 0)
cout << "Num1 / Num2 = " << Num1 / Num2 << endl;
else
cout << "Num2 is not non-zero. Division is not defined. " << endl;
return 0;
}
$ g++ main.cpp $ ./a.out Enter two numbers to be operated with arithmetic operators: 4 6 Num1 + Num2 = 10 Num1 * Num2 = 24 Num1 - Num2 = -2 Num1 / Num2 = 0 $ ./a.out Enter two numbers to be operated with arithmetic operators: 5 0 Num1 + Num2 = 5 Num1 * Num2 = 0 Num1 - Num2 = 5 Num2 is not non-zero. Division is not defined.
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Next Steps:
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Practice Computer Science MCQs
- Apply for Information Technology Internship
- Apply for Computer Science Internship
- Buy C++ Books
- Practice Programming MCQs