Strong number in c

28 Dec 2022 Balmiki Mandal 0 C Programming

Understanding Strong Numbers in C

What is a Strong Number?

  • A strong number (also known as a factorial number) is a number that equals the sum of the factorial of its digits.
  • For example, 145 is a strong number because 1! + 4! + 5! = 145.

How to Determine if a Number is Strong in C?

  1. Calculate Factorials:

  • Break down the number into its individual digits.
  • Calculate the factorial of each digit.
  1. Sum Factorials:

  • Add up all the factorials calculated in the previous step.
  1. Check Equality:

  • Compare the sum obtained in step 2 with the original number.
  • If they are equal, the number is strong.

Write a C Program for Strong Number?

#include 

int factorial(int num) {
    if (num == 0 || num == 1)
        return 1;
    else
        return num * factorial(num - 1);
}

int isStrong(int num) {
    int original = num;
    int sum = 0;

    while (num > 0) {
        int digit = num % 10;
        sum += factorial(digit);
        num /= 10;
    }

    return (sum == original);
}

int main() {
    int num;
    printf("Enter a number: ");
    scanf("%d", &num);

    if (isStrong(num))
        printf("%d is a strong number.", num);
    else
        printf("%d is not a strong number.", num);

    return 0;
}

 

Usage:

  • Copy the provided C code into your preferred C compiler.
  • Input a number to check if it's a strong number.

Conclusion:

  • Strong numbers are an interesting mathematical concept in programming.
  • This C program efficiently determines whether a given number is strong or not.

 

Top Search 

Prime number in c 

Armstrong Number in C 

Strong number in c

Perfect Number in c

palindrome number in c

Fibonacci series in c

Prime number in 1 to 100

Armstrong Number in 1 to 100

Strong number in 1 to 100

Perfect Number in 1 to 100

palindrome number in 1 to 100

Fibonacci series in  1 to 100

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.