Find Strong Number Using C++
First We Need to Know What is Strong Number ?
Strong Number : Strong Number is the Sum of Factorial Of individual Digits of Number
For Example : 145 is a Strong Number means
1!=1;
4!=24;
5!=120;
Strong Number : Strong Number is the Sum of Factorial Of individual Digits of Number
For Example : 145 is a Strong Number means
1!=1;
4!=24;
5!=120;
1! + 4! + 5! = 145
========================================================================
#include<iostream>
using namespace std;
main()
{
int num;
int sum=0;
int digit;
cout<<"Enter A Number\n";
cin>>num;
int i=num;
while(num>0)
{
digit=num%10;
int fact=1;
for(int x=1;x<=digit;x++)
{
fact=fact*x;
}
sum=sum+fact;
num=num/10;
}
if(sum==i)
{
cout<<sum<<" Is A Strong Number \n ";
}
else
cout<<"Is NOT A Strong Number \n";
}
0 comments:
Post a Comment