## Introduction

This blog will discuss the approach to checking whether the given number is a strong number. Before understanding the approach and code, let's first discuss a strong number in C.

## What is a Strong Number in C?

**A strong number is a number where the sum of the factorials of its digits equals the original number**. 1, 2, 145, and 40585 are some examples of Strong numbers.

To check if a number is strong in C, we can calculate the factorial of each digit of the number, add them up, and then compare the result with the original number.

Strong numbers are special and unique in that they are the only ones for which the sum of each digit's factorials matches the actual number.

We will discuss example in below section to understand strong number more clearly.

## Examples of Strong Number

### Example 1

**Input: **

`145`

**Output:**

`145 is a Strong number `

**Explanation: 1**!+4!+5! =1+24+120 =145

Since the sum of the factorial of all digits is equal to the number itself, hence it is a Strong number.

### Example 2

**Input: **

`140 `

**Output:**

`140 is not a Strong number`

**Explanation: **1!+4!+0! =1+24+1 =26

Since the sum of the factorial of all digits is not equal to the number itself, hence it is not a Strong number.

## Algorithm to Check if a Number is a Strong Number or Not in C

Algorithm to check if a number is strong or not in C is as follows:

- Read the input value which is entered by the user
- Declare variable like ‘num’, ‘sum’, ‘temp’ and ‘factorial’
- Initialize the sum of factorials as 0
- Now, create a loop till the input number ‘num’ becomes 0
- Extract the last digit of ‘num’ using the modulo operator and store it in the temp variable
- Calculate the factorial of the value stored in ‘temp’ and store the result in the ‘factorial’ variable
- Add the value of ‘factorial’ to the ‘sum’ variable
- Divide the value of ‘num’ by 10 and remove the last digit
- Compare the sum of factorial ‘sum’ with the original input number
- If ‘sum’ is equal to the input number then it will return that it is a strong number
- If ‘sum’ is not equal to the input number then it will return that it is not a strong number

## Program to Check Whether the Number is a Strong Number or Not.

Program in C to check whether a number is strong or not **using functions**.

**1. Using Functions**

Code

Output

Explanation

In this code, we have used functions to check whether a number is strong. There is an ‘**isStrongNumberOrNot**’ function used to check whether a given number is strong. It nitrates over the digit of the given number and calculates the factorial of it. Then the factorials obtained are summed up together. Then we will check if the sum is equal to the original number; it will return one, which indicates that the number is strong; if it returns 0, it suggests that the number is not strong.

**2. Using For Loops**

Code

Output

Explanation

In this code, we have used **for loops**. We have used the ‘**isStrongNumberOrNot’** function to check whether a given number is strong. We have used the ‘for’ loop to iterate through the digits of the number. Inside the loop, we extract each digit to calculate the factorial of that digit using another ‘for’ loop and then update the sum variable. Then we will check if the sum is equal to the original number; it will return one, which indicates that the number is strong; if it returns 0, it suggests that the number is not strong.

**3. Using While Loop**

Code

Output

Explanation

In this code, we have used a **while loop**. The ‘isStrongNumberOrNot’ function is used to check whether the number is strong or not. We have used the while loop to iterate through the digit the number and for loop to calculate the factorial of that digit and then update the sum variable. Then we will check if the sum is equal to the original number; it will return one, which indicates that the number is strong; if it returns 0, it suggests that the number is not strong.

## Program to Print the Strong Numbers from 1 to n

Output

Explanation

The ‘**isStrong**’ function checks whether a given number is strong in this code. It uses a loop to extract each digit of the number and then add it to the sum variable. If the sum variable is equal to the original number, it will return true; otherwise, it will return false. The ‘printStrong’ function takes input from the user ‘n’ and prints all the strong numbers from 1 to n. It calls the ‘**isStrong**’ function to check whether each number in the range is strong. If a number is strong, it gets printed.

## Program to Find Strong Numbers in a Given Range l,r

Output

Explanation

In this code, users input the range of numbers. The 'isStrong' function checks whether or not each number in the content is strong. The 'findStrongNumber' function takes two integers, 'l' and 'r,' as input to indicate the upper and lower limit of the range. In the main function, the user enters the range value. The function' findStrongNumbers' is used with the provided lower and upper limits as parameters to discover and display all the strong numbers within that specified range.

## Frequently Asked Questions

**What is strong number? **

In mathematics, a number is said to be strong number, if it is a unique number whose factorial sum of its constituent digits is equal to the number itself.

**What is strong number in C using for loop?**

In C, you would compute the factorial of each digit and add them together to find a strong number using a for loop. It is a strong number if the outcome is the same as the starting value.

**Is 871 is a strong number?**

If we calculate the factorial sum of digits of 871, we get that factorial sum of its digits (8! + 7! + 1!) does not equal to 871, hence we can say 871 is not a strong number.

**What is a strong number in C Plus Plus? **

Similar to C, a strong number in C++ is identified by computing the factorial of each digit and verifying that the sum equals the starting value. In such case, it's a solid number.

**Is 145 a strong number? **

A strong number has a sum of factorials of its digits equal to the number itself. In the case of 145, the sum of the factorials of its digits (1! + 4! + 5!) equals 145 thus making it a strong number.

## Conclusion

In this article, we discussed the problem Strong Number in C in which we are given a number ‘n’ and need to check whether the given number is a Strong Number. We hope you understood the problem and solution properly. Now you can do more similar questions. If you are a beginner, interested in coding, and want to learn DSA, you can look for our __Guided path for DSA__, which is free!

Thank you for reading. Until then, Keep Learning and Keep Coding.