You are on page 1of 3

Operators(aritnmetic)

#include<iostream>

using namespace std;

int main(){

int sum,substract,multiple,division;

float a,b;

cout<<"enter any number:";

cin>>a>>b;

sum=a+b;

cout<<"sum of a and b is: "<<a+b<<endl;

substract=a-b;

cout<<"substract of a and b is: "<<a-b<<endl;

multiple=a*b;

cout<<"substract of a and b is: "<<a*b<<endl;

division=a/b;

cout<<"division of a and b is: "<<a/b<<endl;

return 0;

Assignment operator

#include<iostream>

using namespace std;

int main(){

int x;

float y;

cout<<"enter a number:";

cin>>x>>y;

cout<<"you entered:"<<x<<" "<<y;1

return 0;

}
#include<iostream>

using namespace std;

int main(){

// Declare and initialize two integer variables

int number1 = 10;

int number2 = 5;

// Compare number1 and number2 using relational operators

cout << "Is number1 = to number2? " << (number1 == number2) << endl;

cout << "Is number1 != to number2? " << (number1 != number2) << endl;

cout << "Is number1 greater than number2? " << (number1 > number2) << endl;

cout << "Is number1 less than number2? " << (number1 < number2) << endl;

cout << "Is number1 greater than or equal and less than or equal to number2? " << (number1 >=
number2) <<(number1 <= number2)<< endl;

return 0;

#include<iostream>

using namespace std;

int main(){

int a = 10;

int b = 5;

cout << "Addition: " << (a + b) << endl;

cout << "Subtraction: " << (a - b) << endl;


cout << "Multiplication: " << (a * b) << endl;

cout << "Division: " << (a / b) << endl;

cout << "Modulus: " << (a % b) << endl;

// Assignment operators

int x = 10;

x += 5; // Equivalent to x = x + 5;

cout << "After += operator: " << x << endl;

x -= 3; // Equivalent to x = x - 3;

cout << "After -= operator: " << x << endl;

x *= 2; // Equivalent to x = x * 2;

cout << "After *= operator: " << x << endl;

x /= 4; // Equivalent to x = x / 4;

cout << "After /= operator: " << x << endl;

x %= 3; // Equivalent to x = x % 3;

cout << "After %= operator: " << x << endl;

return 0;

You might also like