Program to find the numerology digit of a given number

Calculate the numerology digit for a number. For example, the numerololgy digit for 859 is 4 because 8 + 5 + 9 = 22 and 2 + 2 = 4.

Last Reviewed and Updated on October 26, 2017
Posted by Parveen(Hoven),
Aptitude Trainer and Software Developer

Advertisement

C++ Program to find the numerology digit of a given number.

Ask the user to enter a number. If the user enters a three digit number like 859, then the numerology digit would be 4 because 8 + 5 + 9 = 22, and 2 + 2 = 4. You have to keep adding the digits till you get a single digit.

#include <iostream>
 
using namespace std;
 
int main()
{
    // take a huge data type that can hold
    // phone numbers also
    long long num;
 
    cout << "Enter a number: ";
 
    cin >> num;
 
    int sum = 0;
    
    while(1)
    {
        sum += (num % 10);
 
        num /= 10;
 
        // if the number has 
        // been fully broken down
        if(0 == num)
        {
            // if the sum not a single 
            // digit we have to add 
            // them again
            if(sum > 9)
            {
                num = sum;
 
                sum = 0;
            }
            else
            {
                cout << "Answer: " ;
                
                cout << sum << endl;
 
                return 0;
            }
        }
    };
 
    return 0;
}

My C/C++ Videos on Youtube

Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.



Creative Commons License
This Blog Post/Article "Program to find the numerology digit of a given number" by Parveen (Hoven) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Updated on 2017-10-26.


Advertisement