C Program to Check Strong Number

C program to check strong number; Through this tutorial, we will learn how to check a number is strong or not in c program using for loop, while loop and function.

Programs to Check Strong Number in C

  • C Program to Check Strong Number using While Loop
  • C Program to Check Strong Number using For Loop
  • C Program to Check Strong Number using Function

C Program to Check Strong Number using While Loop

#include <stdio.h>

int main()
{
  int Number, Temp, Reminder, Sum = 0, i;
  long Factorial;

  printf("\nPlease Enter a Number to Check for Strong Number :- ");
  scanf("%d", &Number);

  //Helps to prevent altering the original value
  Temp = Number;
  while( Temp > 0)
   {
     Factorial = 1, i = 1;
     Reminder = Temp % 10;
     while (i <= Reminder)
     {
     	Factorial = Factorial * i;
     	i++;
     }
     printf("\n Factorial of %d = %d\n", Reminder, Factorial);
     Sum = Sum + Factorial;
     Temp = Temp /10;
   }

  printf("\n Sum of the Factorials of a Given Number %d is = %d\n", Number, Sum);

  if ( Number == Sum )
      printf("\n %d is a Strong Number.\n", Number);
  else
      printf("\n %d is not a Strong Number.\n", Number);

  return 0;
}

The output of the above c program; as follows:

Please Enter a Number to Check for Strong Number :- 145
Factorial of 5 = 120

 Factorial of 4 = 24

 Factorial of 1 = 1

 Sum of the Factorials of a Given Number 145 is = 145

 145 is a Strong Number.

C Program to Check Strong Number using For Loop

#include <stdio.h>

int main()
{
  int Number, Temp, Reminder, Sum = 0, i;
  long Factorial;

  printf("\nPlease Enter a Number to Check for Strong Number :- ");
  scanf("%d", &Number);

  //Helps to prevent altering the original value
  Temp = Number;
  for(Temp = Number; Temp > 0; Temp =  Temp / 10 )
   {
     Factorial = 1;
     Reminder = Temp % 10;
     for (i = 1; i <= Reminder; i++)
     {
     	Factorial = Factorial * i;
     }
     printf(" Factorial of %d = %d\n", Reminder, Factorial);
     Sum = Sum + Factorial;
    }

  printf("\n Sum of the Factorials of a Given Number %d is = %d\n", Number, Sum);

  if ( Number == Sum )
      printf("\n %d is a Strong Number.\n", Number);
  else
      printf("\n %d is not a Strong Number.\n", Number);

  return 0;
}

The output of the above c program; as follows:

Please Enter a Number to Check for Strong Number :- 145
Factorial of 5 = 120
 Factorial of 4 = 24
 Factorial of 1 = 1

 Sum of the Factorials of a Given Number 145 is = 145

 145 is a Strong Number.

C Program to Check Strong Number using Function

#include <stdio.h>

long Calculate_Factorial(int);

int main()
{
  int Number, Temp, Reminder, Sum = 0;
  long Factorial;

  printf("\nPlease Enter a Number to Check for Strong Number :- ");
  scanf("%d", &Number);

  //Helps to prevent altering the original value
  Temp = Number;
  for(Temp = Number; Temp > 0; Temp =  Temp / 10 )
  {
     Factorial = 1;
     Reminder = Temp % 10;

     // Calling Calculate_factorial Function
     Factorial = Calculate_Factorial(Reminder);

     printf("Factorial of %d = %d\n", Reminder, Factorial);
     Sum = Sum + Factorial;
   }

   printf("\nSum of the Factorials of a Given Number %d is = %d\n", Number, Sum);

   if ( Number == Sum )
      printf("\n%d is a Strong Number.\n", Number);
   else
      printf("\n%d is not a Strong Number.\n", Number);

   return 0;
}

long Calculate_Factorial(int Number)
{
  if (Number == 0 || Number == 1)
    return 1;

  else
    return Number * Calculate_Factorial (Number -1);
}

The output of the above c program; as follows:

Please Enter a Number to Check for Strong Number :- 145
Factorial of 5 = 120
Factorial of 4 = 24
Factorial of 1 = 1

Sum of the Factorials of a Given Number 145 is = 145

145 is a Strong Number.

Recommended C Programs

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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