Cycle 02
Operators, Expressions & Type Conversions
Evaluation of Arithmetic, Relational, and Logical Operators
Problem Statement
Write a Turbo C++ program to input two numbers and evaluate various Arithmetic (+, -, *, /, %), Relational (<, >, <=, >=, ==, !=), and Logical (&&, ||, !) operators, displaying their evaluated truth values.
#include <iostream.h>
#include <conio.h>
void main() {
int a, b;
clrscr();
cout << "Enter first number (a): ";
cin >> a;
cout << "Enter second number (b): ";
cin >> b;
cout << "\n--- Arithmetic Operations ---" << endl;
cout << "a + b = " << (a + b) << endl;
cout << "a - b = " << (a - b) << endl;
cout << "a * b = " << (a * b) << endl;
cout << "a / b = " << (a / b) << " (Quotient)" << endl;
cout << "a % b = " << (a % b) << " (Remainder)" << endl;
cout << "\n--- Relational Operations (1=True, 0=False) ---" << endl;
cout << "a > b : " << (a > b) << endl;
cout << "a < b : " << (a < b) << endl;
cout << "a == b : " << (a == b) << endl;
cout << "a != b : " << (a != b) << endl;
cout << "\n--- Logical Operations ---" << endl;
cout << "(a > 0 && b > 0) : " << ((a > 0 && b > 0)) << " (Both positive)" << endl;
cout << "(a > 0 || b > 0) : " << ((a > 0 || b > 0)) << " (At least one positive)" << endl;
cout << "!(a == b) : " << (!(a == b)) << endl;
getch();
}
Question 1 of 2