# C Programming – HackerRank Solution | Special Number-5 |

### Write a Modular C Programming code to solve Special Number-5, A number is a special number if the sum of the factorial of the digits is equal to the number.

Suri and Guru are talented students; they always want to be unique in their classes. After research, by referring to some mathematics books, Suri comes with a special number. A number is a special number if the sum of the factorial of the digits is equal to the number. Guru wants to implement the same by using a programming language. Please help Guru to solve the problem by using Problem Solving Framework and Write the modular C program.

Ex1: 145 is a special number.

Explanation

1!+ 4!+5!

1+24+120=145

Input Format

First-line indicates the number ‘N’

Constraints

10<=N<=1000000

Output Format

First-line prints YES if it’s a special number, else NO

Sample Input 0

```2
```

Sample Output 0

```YES
```

Sample Input 1

```25
```

Sample Output 1

`NO`

CODE:

```#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int fact(int dig)
{
int i,fact=1;
for(i=1;i<=dig;i++)
{
fact=fact*i;
}
return fact;
}
void specail(int n)
{
int fact0=1,dig=0,sum=0,copy;
copy=n;
while(n!=0)
{
dig=n%10;
fact0=fact(dig);
sum=sum+fact0;
fact0=1;
dig=0;
n=n/10;
}
if(copy==sum)
printf("YES\n");
else
printf("NO\n");
}
int main() {
int n;
scanf("%d,",&n);
specail(n);
return 0;
}
```

OUTPUT

```Congratulations, you passed the sample test case.

Click the Submit Code button to run your code against all the test cases.

Input (stdin)

2

YES
Expected Output

YES```

Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, MISC, Solved model question papers & Hacker Rank all solutions on the below page:

Top 100+ C Programming codes – KLE Technological University 