Peterson Number

Given a starting number and the ending number the task is to find the all the Peterson Number present in that given range and also to display it’s frequency.

Peterson Number is a number whose sum of factorial to it’s digits are equal to the original number.

Example 1: 145. 1!+4!+5! = 1+24+120 = 145. Hence it is a Peterson Number.

Example 2: 415. 4!+1!+5! = 24+1+120 = 145. Here the result is not equal to the original number. Hence it is not a Peterson Number.

C
#include <stdio.h>
int main() 
{
    int n=0,s=0,r=0,fact=1,nCopy=0;
    printf("Enter a number: ");
    scanf("%d",&n);
    nCopy=n;
    while(n>0)
    {
        r=n%10;
        while(r>0)
        {
            fact=fact*r;
            r--;
        }
        s=s+fact;
        fact=1;
        n=n/10;
    }
    if(s==nCopy)
    {
        printf("%d is a Peterson Number",nCopy);
    }
    else
    {
        printf("%d is not a Peterson Number",nCopy);
    }
    return 0;
}
C