Check for Strong Number

Input a number from user and check if it is an Strong Number or not.
A number is called strong number if sum of the factorial of its digit is equal to number itself.
For example: 145 since 1! + 4! +5! = 1 + 24 + 120 =145

/*
Check for Strong Number
Shaswat Saxena
10/11/2017
*/
#include <stdio.h>
#include <conio.h>
void main ()
{
  int i,num,sum,fact,dig,temp;
  clrscr();
  sum=0;
  printf("Enter the number check\n" );
  scanf("%d",&num);
  temp=num;
  while (temp>0) {
    fact=1;
    dig=temp%10;
    for (i = 1; i <= dig; i++) {
      fact=fact*i;
    }
    sum=sum+fact;
    temp=temp/10;
  }
  if (sum==num) {
    printf("%d is an Strong Number\n",num );
  } else {
    printf("%d is not an Strong Number\n",num );
  }
    getch();
}

Output

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Recommended for You  Find the largest of 3 numbers

Leave a Reply

Close Menu