Search

Strong number in C || C Programs

A number can be said as a strong number when the sum of the factorial of the individual digits is equal to the number.

For example, 145 is a strong number.


Code -

#include <stdio.h> 
int main()  
{  
 int n;  
 int sum=0;  
    printf("Enter a number");  
    scanf("%d",&n);  
 int k=n;  
 int r;  
 while(k!=0)  
    {  
        r=k%10;  
 int f=fact(r);  
        k=k/10;  
        sum=sum+f;  
    }  
 if(sum==n)  
    {  
        printf("\nNumber is a strong");  
    }  
 else 
    {  
        printf("\nNumber is not a strong");  
    }  
 return 0;  
}  
int fact(int r)  
{  
 int mul=1;  
 for(int i=1;i<=r;i++)  
    {  
        mul=mul*i;  
    }  
 return mul;  
 
}  

Output -

Enter the number 145
Number is strong

1 view0 comments

Related Posts

See All

Program of Random Number in C || C Programs

Code - #include <stdio.h> #include <conio.h> #include <stdlib.h> void main() { // use rand() function to generate the number printf (" The random number is: %d", rand()); pri

Getchar() function in C || C Programs

Code - #include <stdio.h> #include <conio.h> void main() { char c; printf ("\n Enter a character \n"); c = getchar(); // get a single character printf(" You have passed ")

  • 1024px-Telegram_logo.svg
  • download
  • YouTube