text: Find all factors of a natural number | Set 1 | A Better ( than Naive ) Solution to find all divisiors ; Function to print the divisors ; Note that this loop runs till square root ; If divisors are equal , print only one ; else Otherwise print both ; Driver program to test above function
code: #include <stdio.h> NEW_LINE #include <math.h> NEW_LINE void printDivisors ( int n ) { for ( int i = 1 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) printf ( " % d ▁ " , i ) ; printf ( " % d ▁ % d ▁ " , i , n / i ) ; } } } int main ( ) { printf ( " The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ STRNEWLINE " ) ; printDivisors ( 100 ) ; return 0 ; }