C Online Compiler
Example: Strong Number or Not in C using Do-while loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Strong Number or Not in C using Do-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 do { i = 1; factorial = 1; reminder = num % 10; do { factorial = factorial * i; i++; } while (i <= reminder); sum = sum + factorial; num /= 10; } while (num); // 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; }
45
Output
Clear
ADVERTISEMENTS