Testing.

Sunday, 29 January 2017

C programming language: C program to check given number is strong number or not.

Strong Number:-
A number is said to be STRONG if the sum of the factorials of its digits is equal to number itself.
   Example:- 145. 1!+4!+5!=1+24+120=125=145.
----------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int n,res=0,i,n1,rem;
int fct;
printf("\nEnter Number: ");
scanf("%d",&n);
n1=n;
while(n)
{
rem=n%10;
fct=1;
for(i=rem;i>=1;i--)
fct=fct*i;
res=res+fct;
n=n/10;
}
if(res==n1)
printf("\n %d Is A Strong Number... ",n1);
else
printf("\n %d Is Not A Strong Number...",n1);
getch();

No comments:

Post a Comment