C PROGRAM FOR STRONG NUMBER OR NOT

   

 

Consider the following I/O samples.


SAMPLE INPUT: 145

SAMPLE OUTPUT: STRONG NUMBER


A number is called a STRONG NUMBER if it leads to it's original number i.e., by performing the sum of factorials of its digits.


145 = 1! + 4! + 5! = 145


C PROGRAM:

#include<stdio.h>

int main()

{

    int n,dig,i,rem,res=0,temp;

    scanf("%d",&n);

    temp=n;

    printf("\n");

    while(n)

    {

        dig=n%10;

        rem=1;

        for(i=1;i<=dig;i++)

            rem=rem*i;

        res+=rem;

        n=n/10;

    }

    if(temp==res)

        printf("STRONG NUMBER");

    else

        printf("NOT A STRONG NUMBER");

    return 0;

}


OUTPUT:





The given source code in C program "FOR STRONG NUMBER OR NOT" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 

If you have any feedback about this article and want to improve this, please comment in the comment section.


Comments

Popular posts from this blog

INVERTED PYRAMID STAR PATTERN

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

Design a way to sort the list of positive integers in the descending order according to frequency of elements. The elements with integers with higher frequency come before with lower frequency elements with same frequency come in the same order as they appear the values.