text: Find all factors of a natural number | Set 1 | A Better ( than Naive ) Solution to find all divisors ; method to print the divisors ; Note that this loop runs till square root ; If divisors are equal , print only one ; Otherwise print both ; Driver method
code: using System ; class GFG { static void printDivisors ( int n ) { for ( int i = 1 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) Console . Write ( i + " ▁ " ) ; else Console . Write ( i + " ▁ " + n / i + " ▁ " ) ; } } } public static void Main ( ) { Console . Write ( " The ▁ divisors ▁ of ▁ " + "100 ▁ are : ▁ STRNEWLINE " ) ; printDivisors ( 100 ) ; } }