Questions:
Write C++ Program to demonstrate the working of Arithmetic Operators
Explanation:
The following table shows all the arithmetic operators supported by the C language.Assume variable numberLeft holds 10 and variable numberRight holds 20, then
Code:
Output:
Write C++ Program to demonstrate the working of Arithmetic Operators
Explanation:
The following table shows all the arithmetic operators supported by the C language.Assume variable numberLeft holds 10 and variable numberRight holds 20, then
Operator | Description | Example |
---|---|---|
+ | Adds two operands. | A + B = 30 |
− | Subtracts second operand from the first. | A − B = 10 |
∗ | Multiplies both operands. | A ∗ B = 200 |
∕ | Divides numerator by de-numerator. | B ∕ A = 2 |
% | Modulus Operator and remainder of after an integer division. | B % A = 0 |
++ | Increment operator increases the integer value by one. | A++ = 11 |
-- | Decrement operator decreases the integer value by one. | A-- = 9 |
Code:
/**************************************************|
/*************C++ Programs AndProjects************|
***************************************************/
#include<iostream>
using namespace std;
void main() {
int numberLeft = 21;
int numberRight = 10;
int Result = 0;
//bellow line will add two
variables
Result
= numberLeft + numberRight;
cout
<< "Line 1 Add Operator
--- Result == "
<< Result << endl;
//bellow line will subtract
two variables
Result
= numberLeft - numberRight;
cout
<< "Line 2 Subtract
Operator--- Result == " << Result << endl;
//bellow line will divide two
variables
Result
= numberLeft / numberRight;
cout
<< "Line 3 Divide
Operator --- Result == " << Result << endl;
//bellow line will multiply
two variables
Result
= numberLeft * numberRight;
cout
<< "Line 4 Multiply
Operator --- Result == " << Result << endl;
//bellow line will take
modulus and store the remainder in result two variables
Result
= numberLeft % numberRight;
cout
<< "Line 5 Modulus
Operator --- Result == " << Result << endl;
//bellow line will increment
in numberLeft
cout
<< "Line 6 Increment
Operator--- Result == " << ++numberLeft << endl;
//bellow line will
Decrement in numberLeft
cout
<< "Line 7 Decrement
Operator --- Result == " << --numberLeft << endl;
}
Output:
0 Questions:
Post a Comment