Alright, so I got this assignment from my instructor. I'll type it out as he wrote it.

An example output would be:

Code:

enter 2 3-digit numbers:
987 567
the input numbers are: 987 567
the digits of the 1st number are: 9, 8, 7
the digits of the 2nd number are: 5, 6, 7
the result is 1554

Now here's the catch. You can't use if statements, arrays, loops, etc. Basically you just have to use math and math functions. I personally couldn't get it. I began ripping my hair out trying to figure it out and said f*ck it and used if statements. Below is the code for both using if statements and the one where I got stuck.

Anyway, I just figured some of you coders out there might like to try this as it really gets your brain thinking (unless I'm totally missing something).

Without further ado, the code:

No if statements:

Code:

#include <iostream>
using namespace std;
int main() {
int num1, num2, a1, a2, a3, b1, b2, b3, r1, r2, r3, r4;
cout << "Please input two 3-digit numbers: ";
cin >> num1 >> num2;
a1 = num1 / 100;
a2 = (num1 - (a1 * 100)) / 10;
a3 = (num1 - ((a1 * 100) + (a2 * 10)));
b1 = num2 / 100;
b2 = (num2 - (b1 * 100)) / 10;
b3 = (num2 - ((b1 * 100) + (b2 * 10)));
r4 = (a3 + b3) - 10;
r3 = (((a3 + b3) - r4) - 10) + ((a2 + b2));
cout << a1 << ", " << a2 << ", " << a3 << endl;
cout << b1 << ", " << b2 << ", " << b3 << endl;
cout << r4 << ", " << r3 << endl;
return 0;}

if statements:

Code:

#include <iostream>
using namespace std;
int main() {
int num1, num2, a1, a2, a3, b1, b2, b3, r1, r2, r3, r4;
r1 = 0;
r2 = 0;
r3 = 0;
r4 = 0;
cout << "Please input two 3-digit numbers: ";
cin >> num1 >> num2;
a1 = num1 / 100;
a2 = (num1 - (a1 * 100)) / 10;
a3 = (num1 - ((a1 * 100) + (a2 * 10)));
b1 = num2 / 100;
b2 = (num2 - (b1 * 100)) / 10;
b3 = (num2 - ((b1 * 100) + (b2 * 10)));
r4 = a3 + b3;
if (r4 > 10) {
r4 -= 10;
r3 += 1;}
r3 += a2 + b2;
if (r3 > 10) {
r3 -= 10;
r2 += 1;}
r2 += a1 + b1;
if (r2 > 10) {
r2 -= 10;
r1 = 1;}
cout << a1 << ", " << a2 << ", " << a3 << endl;
cout << b1 << ", " << b2 << ", " << b3 << endl;
if (r1)
cout << r1 << r2 << r3 << r4 << endl;
else
cout << r2 << r3 << r4 << endl;
return 0;}