Strong Number C Program

By | August 12, 2016

C Program To Find Strong Number

Learn How To Find Strong Number in C Programming Language. Check if a Number is a Strong Integer not in C Programming using Functions, While and For Loops. It is important that we should know How A For Loop Works before getting further with the C Program Code. Strong Number makes use of the Factorial Concept in C Programming.

What is a Strong Number?

A Number is said to be a Strong Number if the Sum of the Factorials of the Digits of a Number is equal to the Number itself.

Example

145 = (1!) + (4!) + (5!)
40585 = (4!) + (0!) + (5!) + (8!) + (5!)

Must Read: C Program To Print Prime Numbers from 1 To N

C Program To Find Strong Number using For Loop

#include<stdio.h>
 
int main()
{
      int num, count, fact, rem, sum = 0, temp;
      printf("Enter a Number:\t");
      scanf("%d", &num);
      for(temp = num; num > 0; num = num / 10)
      {
            fact = 1;
            rem = num % 10;
            for(count = 1; count <= rem; count++)
            {
                  fact = fact * count;	
            } 
            sum = sum + fact;
      }
      if(sum == temp)
      {
            printf("%d is a Strong Integer\n\n", temp);
      }
      else
      {
            printf("%d is Not a Strong Integer\n\n", temp);
      }
      return 0; 
}

Must Read: C Program To Find Strong Numbers from 1 To N

C Program To Check Strong Number using Functions

#include<stdio.h>
 
int factorial(int value)
{
      int count, fact = 1;
      for(count = 1; count <= value; count++)
      {
            fact = fact * count;
      }
      return fact;
}
 
int main()
{
      int num, count, result, rem, sum = 0, temp;
      printf("Enter a Number:\t");
      scanf("%d", &num);
      temp = num;
      for(temp = num; num > 0; num = num / 10)
      {
            count = 1, result = 1;
            rem = num % 10;
            result = factorial(rem);
            sum = sum + result;
      }
      if(sum == temp)
      {
            printf("%d is a Strong Integer\n\n", temp);
      }
      else
      {
            printf("%d is Not a Strong Integer\n\n", temp);
      }
      return 0;
}

C Program To Display Strong Numbers using While Loop

#include<stdio.h>
 
int main()
{
      int num, count, fact, rem, sum = 0, temp;
      printf("Enter a Number:\t");
      scanf("%d", &num);
      temp = num;
      while(num)
      {
            count = 1, fact = 1;
            rem = num % 10;
            while(count <= rem)
            {
                  fact = fact * count;
                  count++;
            } 
            sum = sum + fact;
            num = num / 10;
      }
      if(sum == temp)
      {
            printf("%d is a Strong Integer\n\n", temp);
      }
      else
      {
            printf("%d is Not a Strong Integer\n\n", temp);
      }
      return 0; 
}

Output

C Program To Find Strong Number using Function, For Loop and While Loop
Must Read: C Program To Find Special Numbers from 1 To N

 

In case you get any Compilation Errors or any doubts in this C Program To Find Strong Integers, let us know about it in the Comment Section below.

5 thoughts on “Strong Number C Program

  1. Sharmila Yadav

    Is there any similarity between Strong Numbers and Armstrong Numbers in C Programming?

    Reply
  2. Sharmila Yadav

    Is this Strong Number C Program frequently asked in the interview question? It seems a little tricky but easy to understand.

    Reply
    1. Tushar Soni Post author

      I don’t think so. But, it’s an important concept that you must know. You never know if the interviewer asks you a program that has a similar concept! Try to understand the concept which is more important.

      Reply

Let's Discuss