Hi, I am in need of some quick help with my code. It is supposed to test all three digit numbers for when the sum and product of the individual digits are equal. When I run it as is, it just repeatedly prints 123 (which is the first of the 3 digit numbers to satisfy the conditions). a,b, and c are representing each digit of the number with i representing each the number being tested. All help and advice appreciated! Thank you in advance!
#include <iostream>
using namespace std;
int main()
{
int i;
int sum = 0;
int product = 0;
for (i=100; 100<=i<999; i++) {
int a = i / 100;
int b = i % 10;
int c = (i / 10) % 10;
sum = a + b + c;
product = a * b * c;
while(sum==product) {
cout << i << endl;
}
}
return 0;
}
Sorry, this is probably poorly coded. However what I'm trying to accomplish is to print the numbers that would satisfy these conditions. For example, 123 would work because:
1+2+3=6
and
1*2*3=6.
Sorry about that. It is looking for when the product and sum of the three individual digits are the same.
132: 1+3+2=6, and 1*3*2=6, and 6=6.
231: 2+3+1=6, and 2*3*1=6, and 6=6.
I'm sorry, I'd give more examples but I don't know that there are more than just ones whose digits are 1, 2 and 3.
But what it is supposed to do is print the numbers that have an equal product and sum like the above examples do.