text: Find all divisors of a natural number | Set 2 | A O ( sqrt ( n ) ) program that prints all divisors in sorted order ; function to print the divisors ; Driver program to test above function
code: #include <stdio.h> NEW_LINE #include <math.h> NEW_LINE void printDivisors ( int n ) { int i ; for ( i = 1 ; i * i < n ; i ++ ) { if ( n % i == 0 ) printf ( " % d ▁ " , i ) ; } if ( i - ( n / i ) == 1 ) { i -- ; } for ( ; i >= 1 ; i -- ) { if ( n % i == 0 ) printf ( " % d ▁ " , n / i ) ; } } int main ( ) { printf ( " The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ STRNEWLINE " ) ; printDivisors ( 100 ) ; return 0 ; }