What is a strong number?

A number can be said as a strong number if the sum of factorial of all the digits is equal to the number. To check that a number is strong number or not, we have to determine the sum of factorial of all the digits of that number. Then, if the sum is = number then the number will be a strong number.

Now, lets think about a number 263. The value of this number is 263. Let’s determine the sum of factorial of digits for this number.

2! + 6! + 3!

= 2 + 720 + 6

728

We all are well clear that 263 is not equal to 728. And for this 263 is not a strong number.

Let’s think about another number which is 145.

1! + 4! + 5!

1 + 24 + 120

145

Here, 145 is equal to 145. So, 145 will be a strong number.

Here in this article we will see some program related to strong number in C. So, let’s get started.

Check strong number program in C

In this program we will take the number from user and check. If the number is a strong number then we will print the number is strong otherwise not. Let’s go to the code.

// checking strong number program in C

#include <stdio.h>

int fact_funct(int rem){
  int c, multiply = 1;
  for(c = 1; c <= rem; c++){
    multiply *= c;
  }
  return multiply;
}

int main(){
    int number, factorial, reminder, i, sum = 0;
    printf("Enter a number number to check strong : ");
    scanf("%d",&number);
    i = number;
    while(i != 0){
        reminder = i % 10;
        int factorial = fact_funct(reminder);
        i /= 10;
        sum += factorial;
    }
    if(sum == number){
        printf("\n%d is a strong number.\n", number);
    }else{
        printf("\n%d is not a strong number.\n", number);
    }
    return 0;
}

Output of this strong number program :

check-strong-number-in-c-c-strong-number

C program to print n strong numbers

In this program we will take an integer input from the user and print all the strong number between 1 to n. We can do the program using some different way. Let’s see how the program looks like.

// print n strong numbers

#include<stdio.h>

int factorials(int fact){
  int j, multiply = 1;

  for(j = 1; j <= fact; j++){
    multiply *= j;
  }

  return multiply;
}

int main(){
  int c, d, num, rem, f = 1, sum = 0;

  printf("Enter the number n here : ");
  scanf("%d",&num);

  printf("\nStrong numbers from 1 to %d are : \n", num);

  for(c = 1; c <= num; c++){
    d = c;

    while(d != 0){
      rem = d % 10;
      f = factorials(rem);
      d = d / 10;
      sum = sum + f;
    }

    if(sum == c){
    printf("%d ", c);
    }

    sum = 0;

  }

  return 0;
}

Output :

Enter the number n here : 5000

Strong numbers from 1 to 5000 are :
1 2 145

Find strong numbers between two integer

This program will find all the strong numbers between your given range. We will take two integer from the user. First will be the lower limit and last integer will be the upper limit. Then we will find all the strong numbers between two given integers.

// strong numbers between two given range

#include<stdio.h>

int func_fact(int fact);

int main(){
  int num1, num2, f = 1, sum = 0, rem, j, c;

  printf("Enter the first number here : ");
  scanf("%d",&num1);

  printf("\nEnter the last number here : ");
  scanf("%d",&num2);

  printf("\nStrong numbers between %d and %d are : \n", num1, num2);

  for(j = num1; j <= num2; j++){
    c = j;
    while(c != 0){
      rem = c % 10;
      f = func_fact(rem);
      c = c / 10;
      sum += f;
    }
    if(sum == j){
      printf("%d, ", j);
    }
    sum = 0;
  }
  return 0;
}

int func_fact(int fact){
  int k, multiply = 1;
  for(k = 1; k <= fact; k++){
    multiply = multiply * k;
  }
  return multiply;
}

Output of this program :

Enter the first number here : 2

Enter the last number here : 500

Strong numbers between 2 and 500 are :
2, 145,

Previous pageCount digits program

Next pagePerfect number program