Headlines
Loading...
C program to find if a given number is a strong number

C program to find if a given number is a strong number

Write a c program to find if a given number is a strong number. ( If the sum of the factorials of all digits of a number are equal to the number, its called a strong number. ) 

 

#include<stdio.h>

#include<conio.h>

void main()

{

int no,a[5],temp,i=0,j,fac[5]={1,1,1,1,1},k,sum;

clrscr();

printf("Enter any number(Less than (32767)");

scanf("%d",&no);

temp=no;

while(no!=0)

            {

            a[i]=no%10;

            printf("%d\t",a[i]);

            no=no/10;

            i++;

            }

printf("\n\n\n");

j=0;

do

{

for(k=1;k<=a[j];k++)

            {

 

            fac[j]=fac[j]*k;

 

 

            }

printf("\na[j]=%d\tfac[j]=%d\n",a[j],fac[j]);

j++;

}while(j<i);

for(j=0;j<i;j++)

            {

            sum+=fac[j];

            }

printf("\nsum=%d",sum);

if(sum==temp)

            {

            printf("\nThe number entered is a strong number");

            }

 

else

            {

            printf("\nThe number entered is NOT a strong number");

            }

getch();

}

 

/* Output

Enter any number(Less than (32767)1

1

 

 

 

a[j]=1  fac[j]=1

 

sum=4612

The number entered is NOT a strong number

*/
*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***