strong Number Algorithm

The strong number algorithm is a mathematical method used to determine if a given number is a strong number or not. A strong number is defined as a number for which the sum of the factorials of its digits is equal to the number itself. Factorial is a mathematical operation that involves multiplying a number by all the positive integers smaller than it. For example, the factorial of 4 is 4 * 3 * 2 * 1 = 24. The strong number algorithm essentially breaks down a number into its individual digits, calculates the factorial of each digit, and then sums up these factorials to check if the result is equal to the original number. The strong number algorithm comprises the following steps: 1. Take the input number and store it in a variable, say 'num'. 2. Initialize a variable, say 'sum', to store the sum of factorials of the digits. 3. Extract the individual digits of the number by using modulo arithmetic and division. For each digit, calculate its factorial and add it to the 'sum' variable. 4. After processing all the digits, compare the 'sum' variable with the original number 'num'. If they are equal, then the number is a strong number; otherwise, it is not. For example, let's consider the number 145. The strong number algorithm would first calculate the factorials of each digit, i.e., 1! = 1, 4! = 24, and 5! = 120. Then, it would sum these factorials, resulting in 1 + 24 + 120 = 145. Since the sum of the factorials is equal to the original number, 145 is a strong number.
/**
 * Modified on 07/12/2017, Kyler Smith
 *
 * A number is called strong number if sum of the 
 * 	factorial of its digit is equal to number itself.
 */

#include<stdio.h>


void strng(int a)
{
	int j=a;
	int sum=0;
	int b,i,fact=1;	
	while(a>0)
	{
		fact=1;
		b=a%10;
		for(i=1;i<=b;i++)
		{
			fact=fact*i;
		}
		a=a/10;
		sum=sum+fact;
	}
	if(sum==j)
	printf("%d is a strong number",j);
	else
	printf("%d is not a strong number",j);
}
void main()
{
	int a;
	printf("Enter the number to check");
	scanf("%d",&a);
	strng(a);
}

LANGUAGE:

DARK MODE: