Strong number is a number whose sum of the factorial of digits of number is equal to given number.
For Example:
145 is a strong number.
Let's check this number is strong number or not.
1! + 4! + 5! = 1 + 24 + 120 = 145
So 145 is a strong number.
// Check given number is strong number c program
#include<stdio.h>
int factorial(int i);
int main(){
int n;
printf("Enter the Number : ");
scanf("%d", &n);
int temp = n, sum = 0;
while(temp>0){
int digit = temp%10;
sum = sum + factorial(digit);
temp = temp / 10;
}
if(sum == n){
printf("%d is a Strong Number", n);
}else{
printf("%d is not Strong Number", n);
}
return 0;
}
int factorial(int i){
int fact = 1;
for(int j=1; j<=i; j++){
fact = fact * j;
}
return fact;
}
In factorial function, initialized a variable fact and assigned the value 1. Start for loop, in for loop we initialized a variable j = 1 and the condition is j ≤1 and increment the value of j by 1. And perform the operation after goes to loop body this expression (face = fact * j). When loop is terminated. Then we return the value of fact.
Comments
Oops!