Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Strong Numbers in 1 to 100 in C

Last Updated on May 15, 2023 by Prepbytes

This blog post will go through how to determine whether a given number is a strong one. Let’s first talk about a strong number in C before explaining the strategy and code.

What are Strong Numbers in C Language?

A strong number is one in which the factorial of each digit of a number equals the original number’s sum.

Example of strong number in C: 145 is a strong number. To see if 145 is a strong number, we must compute and add the factorials of its digits:

1! + 4! + 5! = 1 + 24 + 120 = 145

145 is a strong number because the sum of its factorials is equal to the number itself.

Algorithm to Find Strong Numbers in 1 to 100

Using the algorithm below, we can find the strong numbers ranging from 1 to 100.

  1. Set the variable num to one.
  2. While num is less than or equal to 100, repeat the loop.
  3. Make a variable sum equal to zero.
  4. Iterate over the characters of num after converting it to a string.
  5. Calculate the factorial of each character and add it to the total.
  6. If sum equals num, print num.
  7. Repeat step 2 by increasing the number by one.

Pseudo Code to Find Strong Numbers in 1 to 100

set num to 1
while num <= 100
    set the sum to 0
    for each digit in num converted to string
        set factorial to 1
        for i from 1 to digit
            set factorial to factorial * i
        add factorial to sum
    if sum == num
        print num
    increment num by 1

Code Implementation to Find Strong Numbers in 1 to 100 in C

#include <stdio.h>
int factorial(int n) {
    int fact = 1;
    for(int i=1; i<=n; i++) {
        fact *= i;
    }
    return fact;
}
int isStrongNumber(int num) {
    int sum = 0;
    int temp = num;
    while(temp != 0) {
        int rem = temp % 10;
        sum += factorial(rem);
        temp /= 10;
    }
    return (sum == num);
}

int main() {
    printf("Strong numbers from 1 to 100 are:\n");
    for(int i=1; i<=100; i++) {
        if(isStrongNumber(i)) {
            printf("%d ", i);
        }
    }
    return 0;
}

Output:

Strong numbers from 1 to 100 are:
1 2 

Conclusion
To summarize, a strong number is a type of number in which the sum of its factorials equals the original number. This article's algorithm and code show how to find strong numbers from 1 to 100 by iterating over each number and calculating the sum of its factorial digits. The C language code implementation provides a practical example of how to find strong numbers, and the output displays strong numbers between 1 and 100. This strong number concept is an intriguing mathematical concept that can be applied in a variety of areas of computer science and mathematics.

Frequently Asked Questions (FAQs)

Q1. Why is 145 a strong number?
Ans. In this case, 145 is a strong number because the sum of the factorial of digits equals the number itself.

Q2. Is 2 a strong number?
Ans. A strong number is one in which the factorial of the digits equals the number itself. 1, 2, 145, and 40585 are some examples of strong numbers.

Q3. What is meant by a strong number?
Ans. A strong number is one whose factorial sum of all digits equals the number "n." When we find the product of all the numbers below that number, including that number, we get a factorial, which is denoted by!.

Leave a Reply

Your email address will not be published. Required fields are marked *