To add all the digits of a number till you get a single digit. code example
Example: To add all the digits of a number till you get a single digit.
#include
using namespace std;
int digSum(int n)
{
if (n == 0)
return 0;
return (n % 9 == 0) ? 9 : (n % 9);
}
int main()
{
int n = 9999;
cout<