You're online now.

Hurray! you are online now.

Strong Number in C programming What is Strong Number

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;
    }
  1.  START the program
  2. Include header file “stdio.h”
  3. Declare a function (for calculate the factorial)
  4. Start main() function
  5. Initialized a variable n, which store the given number by user for checking the strong number.
  6. Print message for user.
  7. Take input from scanf() function.
  8. Initialized another variable temp and sum, temp is used to temporary variable which store the original number and sum is used for store the ans whose initial assigned zero()
  9. Start a while loop, and here given the condition when (temp > 0), when condition is true then execute the loop body statement REPEATE all (step 10, 11, 12).
  10. Initialized a variable digit, whose store the last digit of the number.
  11. Execute this sum = sum + factorial(digit);
    When factorial(digit) is called then go to the this function definition.
  12. REMOVE the last digit, with the help of this (temp = temp / 10).
  13. CHECK that given number is equal to sum, if the condition is true then print given number is a strong number otherwise both are not equal the print given number is not a strong number.
  14. RETURN 0 (exit).

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.

🖤 0
Buy me coffee ☕

Comments

Oops!

No comments here...