Thursday 18 April 2019

Program to check if a given number is a strong number or not

Program to check if a given number is a strong number or not is discussed here. A strong number is a number in which the sum of the factorial of the digits is equal to the number itself.
check if a given number is strong number or not
#include<bits/stdc++.h>
using namespace std;
int fact(int num)
{
int res=1;
while(num>0)
{
res*=(num--);
}
return res;
}
bool isStrong(int num)
{
int p=num;
int res=0;
while(p>0)
{
res+=fact(p%10);
p/=10;
}
if(res==num)
return 1;
return 0;
}



int main()
{
int num=123;
cout<<isStrong(num);
}

No comments:

Post a Comment

Amazon1Ads