C Online Compiler
Example: Strong Number or Not in C using For loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Strong Number or Not in C using For 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) { // Step-3 Use a loop to check the number for (int k = num; k > 0; k /= 10) { factorial = 1; reminder = k % 10; for (int i = 1; i <= reminder; i++) factorial = factorial * i; sum = sum + factorial; } // Step-4 Compare the value of the sum of digits with the original input value if (sum == num) printf("%d IS A STRONG NUMBER.\n", num); else printf("%d IS NOT A STRONG NUMBER.\n", num); } else printf("Enter a positive number!\n"); return 0; }
40585
Output
Clear
ADVERTISEMENTS