C Online Compiler
Example: Strong Number or Not in C using While loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Strong Number or Not in C using While loop #include <stdio.h> // It's the main function of the program int main() { int num, factorial, reminder, sum = 0; // Step-1 Take input from the User printf("INPUT A NUMBER: "); scanf("%d", &num); // Step-2 Check input number should be positive if (num > 0) { int original = num, i; // Step-3 Use a loop to check the number while (num) { i = 1; factorial = 1; reminder = num % 10; while (i <= reminder) { factorial = factorial * i; i++; } sum = sum + factorial; num /= 10; } // Step-4 Compare the value of the sum of digits with the original input value if (sum == original) printf("%d IS A STRONG NUMBER.\n", original); else printf("%d IS NOT A STRONG NUMBER.\n", original); } else printf("Enter a positive number!\n"); return 0; }
145
Output
Clear
ADVERTISEMENTS