Write a program which takes two integers (num1 and num2) as input from the user.
Your program should display on the screen the result of i) num1 + num2, ii) num1 * num2, and iii) num1 - num2.
You are not allowed to use the + or - or * operators. E.g., cout<<num1+num1<<num1*num2<<num1-num2; is not allowed. += or -= or *= operators are also not allowed.
You HAVE TO USE loops and the ++ and -- operators. Code for num1+num2 is already available in the slides. Use that for this assignment.
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
cin >> num1 >> num2;
int a = num1;
for (int i = 0; i < num2; i++)
a++;
int b = 0;
for (int i = 0; i < num1; i++)
for (int j = 0; j < num2; j++)
b++;
int c = num1;
for (int i = 0; i < num2; i++)
c--;
cout << a << endl;
cout << b << endl;
cout << c << endl;
}
Comments
Leave a comment