C program to check the given number is a strong number or not
When the sum of the factorial of a number’s individual digits is equal to the number itself, then we can say that number is called a strong number.
For example: 145 is a strong number
Since, 1! + 4! + 5!
= 145
So, let’s move forward to our code:
#include <stdio.h> #include<conio.h> void main() { int i, num, num1, s1=0,j; long facto; //clrscr(); printf("\n...Welcome To EduNews.Tech... "); printf("\n\nCheck whether a number is Strong Number or not:\n "); /* If sum of factorial of digits is equal to original number then it is Strong number */ printf("Enter a number to check it is Strong number: "); scanf("%d", &num); num1 = num; for(j=num;j>0;j=j/10) { facto = 1; for(i=1; i<=j % 10; i++) { facto = facto* i; } s1 = s1 + facto; } if(s1==num1) { printf("%d is Strong number.\n", num1); } else { printf("%d is not Strong number.\n", num1); } printf("\n\n\n\t\t\tThankyou for Joining Us !"); printf("\n\t\t\t!Regards EduNews !"); getch(); }
Program Output:
I hope this post helps you to understand Strong number and its implementation in C programming language.
Keep coding 🙂
Excellent
Nicely done
classy example