Given Number is Strong number or Not Program in c language

Given Number is Strong number or Not Program in c language:

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;
}

Result

Enter a number: 145
145 is a strong number

 

Leave a Reply

Your email address will not be published.