Find all divisors of first N natural numbers | C ++ implementation to find all the divisors of the first N natural numbers ; Function to find the factors of the numbers from 1 to N ; Loop to find the factors of the first N natural numbers of the integer ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void factors ( int n ) { int i , j ; cout << "1 ▁ - - > 1 STRNEWLINE " ; for ( i = 2 ; i <= n ; i ++ ) { cout << i << " ▁ - - > " ; for ( j = 1 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { cout << j << " , ▁ " ; if ( i / j != j ) cout << i / j << " , ▁ " ; } } cout << " STRNEWLINE " ; } } int main ( ) { int n = 5 ; factors ( n ) ; }