Program to check Strong number in C++

What is Strong Number?

Strong Number is one in which sum of factorial of digits of a number is equals to the number.

For example: 145.

Sum of factorials of digits i.e. 1! + 4! + 5! = 1 + 24 + 120 = 145

Therefore 145 is a Strong Number.

 Program to check Strong number in C++:

#include<iostream>
using namespace std;

int main()
{
  int num,i,f,r,sum=0,temp;

  cout << "Enter a number: ";
  cin >> num;

  temp=num;
  while(num){
      i=1,f=1;
      r=num%10;

      while(i<=r){
         f=f*i;
        i++;
      }
      sum=sum+f;
      num=num/10;
  }
  if(sum==temp)
     cout << temp << " is a strong number";
  else
     cout << temp << " is not a strong number";

  return 0;
}

 

OUTPUT:

Strong number in c++

Leave a Comment