C++ Program to check whether given number is Strong number or not [DEVCPP/GCC]

STRONG NUMBER

A number is said to be a strong number if the sum of factorial of its individual digits is equal to the number itself.

eg. 145 = 1! + 4! + 5!
             = 1 + 24 + 120
             = 145

PROGRAM

//Program to check whether given number is Strong number or not

#include <iostream>

using namespace std;

int factorial(int n)
{
         int fact=1;

         while(n>0)
        {
                fact=fact*n;
                n--;
         }

         return fact;
}

int main()
{
        int num,numc,digit,sum=0;

        cout<<"ENTER NUMBER: ";
        cin>>num;

        numc=num;

        while(numc>0)
        {
                digit=numc%10;
                sum=sum+factorial(digit);
                numc=numc/10;
        }

         if(num==sum)
         {
                cout<<num<<" IS A STRONG NUMBER";
         }
         else
         {
               cout<<num<<" IS NOT A STRONG NUMBER";
         }

         return 0;
}

OUTPUT

C++ Program to check whether given number is Strong number or not with output

Share this

Related Posts

FIND US ON FACEBOOK!