Arithmetic Operator Examples with source code in C++ - Compound Arithmetic Expression - Learn C++

 

Arithmetic Operator Examples with source code in C++ - Compound Arithmetic Expression - Learn C++

Arithmetic Operator Examples with source code:

  • Take input from user and perform the arithmetic operation on the input: 

Source Code:


#include<iostream>
using namespace std;
int main(){
    int x;
    int y;
    cout<<"Enter the value of 1st number"<<endl;
    cin>>x;
    cout<<"Enter the value of 2nd number"<<endl;
    cin>>y;
    cout<<"The sum is :"<<x+y;
    return 0;
}

Output:
Arithmetic Operator Examples with source code in C++ - Compound Arithmetic Expression - Learn C++

Compound Arithmetic Expression:

  • If multiple operators appear in the same expression, multiplication, division, modulus ,addition and subtraction.
Source Code:

#include<iostream>
using namespace std;
int main(){
    int a=4;
    int b=7;
    int c=5;
    int d=2;
    int f;
    f=2*(a+3*(b+4*(c+5*d)));
    cout<<f;
    return 0;
}

Output:
Arithmetic Operator Examples with source code in C++ - Compound Arithmetic Expression - Learn C++




Post a Comment

0 Comments