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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #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
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.
Is there any similarity between Strong Numbers and Armstrong Numbers in C Programming?
Not at all. Apart from a small similarity in the name, there are no other similarities Sharmila.
Is this Strong Number C Program frequently asked in the interview question? It seems a little tricky but easy to understand.
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.
Thank you CodingAlpha for so many methods of finding Strong Numbers.