I know the answer is probably very simple, but I've nearly exhausted myself trying everything I know in c++, which isn't much. The first function works, to my knowledge, I just can't get the loop to terminate.
#include <iostream>
#include <cstdlib>
using namespace std;
unsigned int reverseInt(unsigned int num)
{
unsigned int rem, reverse;
while(num > 0)
{
rem = num % 10;
reverse = reverse * 10 + rem;
num /= 10;
}
return reverse;
}
unsigned int generateSequence(unsigned int num, ostream& out)
{
unsigned int k = 0;
while(num != 1)
{
num = num + 4;
num = reverseInt(num);
k++;
out << ", " << num;
}
out << endl;
return k;
}
mainwould be nice and you have to tell us what input you used4tonumeventually make it equal to1? What ifnumstarts as5?reverse, it would reach 1 after 52 steps whennumstarts as 5.