Operators
Operators
Write a program that takes two integers as input and performs the following operations:
Addition
Subtraction
Multiplication
Division
Modulus
cpp
Copy code
#include <iostream>
using namespace std;
int main() {
int a, b;
cout << "Enter two integers: ";
cin >> a >> b;
return 0;
}
Create a program that compares two floating-point numbers and prints whether the first is
greater than, less than, or equal to the second.
cpp
Copy code
#include <iostream>
using namespace std;
int main() {
float num1, num2;
cout << "Enter two floating-point numbers: ";
cin >> num1 >> num2;
return 0;
}
cpp
Copy code
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter a number: ";
cin >> number;
return 0;
}
Create a simple calculator program that performs addition, subtraction, multiplication, and
division. Use assignment operators to store the results.
cpp
Copy code
#include <iostream>
using namespace std;
int main() {
int a, b;
cout << "Enter two integers: ";
cin >> a >> b;
int result = 0;
result -= b; // Subtract b
cout << "Difference: " << result << endl;
result *= a; // Multiplication
cout << "Product: " << result << endl;
if (b != 0) {
result /= b; // Division
cout << "Quotient: " << result << endl;
} else {
cout << "Cannot divide by zero!" << endl;
}
return 0;
}
Exercise 5: Increment and Decrement Operators
Write a program that demonstrates the use of increment (++) and decrement (--) operators.
cpp
Copy code
#include <iostream>
using namespace std;
int main() {
int count = 5;
// Pre-increment
cout << "Pre-increment: " << ++count << endl;
// Post-increment
cout << "Post-increment: " << count++ << endl;
cout << "Count after post-increment: " << count << endl;
// Pre-decrement
cout << "Pre-decrement: " << --count << endl;
// Post-decrement
cout << "Post-decrement: " << count-- << endl;
cout << "Count after post-decrement: " << count << endl;
return 0;
}