Friday, June 26, 2020

Strong Number in C

Strong number in C

PROBLEM STATEMENT:

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.

PROGRAM:

#include<stdio.h>
int main() 
{
    int i,a,n,c,fact,sum=0;
    scanf("%d",&n);
    int t=n;
    while(n>0)
    {
        a=n%10;
        fact=1;
        for(i=1;i<=a;i++)
        {
            fact=fact*i;
        }
        sum=sum+fact;
        n=n/10;
    }
    if(t==sum)
        printf("Strong number");
    else
        printf("Not a strong number");
        
    return 0;
}
       
OUTPUT:

145                                                                                                                   
Strong number   

No comments:

Post a Comment