CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;
int main() {
// Task 1: Arithmetic Operators
int num1, num2;
// Taking input from the user
cout << "Enter two integers: ";
cin >> num1 >> num2;
// Performing arithmetic operations
cout << "Addition: " << num1 << " + " << num2 << " = " << num1 + num2 << endl;
cout << "Subtraction: " << num1 << " - " << num2 << " = " << num1 - num2 << endl;
cout << "Multiplication: " << num1 << " * " << num2 << " = " << num1 * num2 << endl;
// Handling division and modulus safely
if (num2 != 0) {
cout << "Division: " << num1 << " / " << num2 << " = " << num1 / num2 << endl;
cout << "Modulus: " << num1 << " % " << num2 << " = " << num1 % num2 << endl;
} else {
cout << "Division and modulus by zero are not allowed." << endl;
}
// Task 2: Comparison Operators
cout << "\nComparison Results:" << endl;
cout << num1 << " > " << num2 << " : " << (num1 > num2) << endl;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Ejecutar