Program to find all Factors of a Number using recursion | C ++ program to find all the factors of a number using recursion ; Recursive function to print factors of a number ; Checking if the number is less than N ; Calling the function recursively for the next number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void factors ( int n , int i ) { if ( i <= n ) { if ( n % i == 0 ) { cout << i << " ▁ " ; } factors ( n , i + 1 ) ; } } int main ( ) { int N = 16 ; factors ( N , 1 ) ; }