C Online Compiler
Example: C Program to Find Factors of a Number using Recursion
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Find Factors of a Number using Recursion #include <stdio.h> // It's the recursive function // It will display the factors void Factors(int x, int i) { if (i <= x) { if (x % i == 0) { printf("%d ", i); } // Calling function itself to print the next number Factors(x, i + 1); } } // It's the driver function int main() { int x; printf("-----Enter the positive integer number-----\n"); scanf("%d", &x); printf("\nThe factors of the %d are: ", x); Factors(x, 1); printf("\n"); return 0; }
120
Output
Clear
ADVERTISEMENTS