Here is a digital square root calculator in 26 lines.
#include <iostream>
#include <string>
unsigned digitalRoot(std::ostream &ostr, unsigned input)
{
unsigned root = 0;
while (input > 0)
{
unsigned digit = input % 10;
root += digit;
input /= 10;
ostr << digit << " + ";
}
ostr << "\b\b\b = " << root << std::endl;
return root < 10 ? root : digitalRoot(ostr, root);
}
int main()
{
std::string input;
std::cout << "Please enter a number: ";
std::getline(std::cin, input);
std::cout << "\nDigital root is " << digitalRoot(std::cout, (unsigned long long)std::stoi(input)) << ".\n\n";
main();
return 0;
}