Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>JUST one line</strong><br> I have thought very carefuly about your question and I have tried to write a highly efficient and performant piece of code To print all divisors of a given number on screen we need just one line of code! (use option -std=c99 while compiling via gcc)</p> <pre><code>for(int i=1,n=9;((!(n%i)) &amp;&amp; printf("%d is a divisor of %d\n",i,n)) || i&lt;=(n/2);i++);//n is your number </code></pre> <p>for finding numbers of divisors you can use the following very very fast function(work correctly for all integer number except 1 and 2)</p> <pre><code>int number_of_divisors(int n) { int counter,i; for(counter=0,i=1;(!(n%i) &amp;&amp; (counter++)) || i&lt;=(n/2);i++); return counter; } </code></pre> <p>or if you treat given number as a divisor(work correctly for all integer number except 1 and 2) </p> <pre><code>int number_of_divisors(int n) { int counter,i; for(counter=0,i=1;(!(n%i) &amp;&amp; (counter++)) || i&lt;=(n/2);i++); return ++counter; } </code></pre> <p>NOTE:two above functions works correctly for all positive integer number except number 1 and 2 so it is functional for all numbers that are greater than 2 but if you Need to cover 1 and 2 , you can use one of the following functions( a little slower)</p> <pre><code>int number_of_divisors(int n) { int counter,i; for(counter=0,i=1;(!(n%i) &amp;&amp; (counter++)) || i&lt;=(n/2);i++); if (n==2 || n==1) { return counter; } return ++counter; } </code></pre> <p>OR</p> <pre><code>int number_of_divisors(int n) { int counter,i; for(counter=0,i=1;(!(i==n) &amp;&amp; !(n%i) &amp;&amp; (counter++)) || i&lt;=(n/2);i++); return ++counter; } </code></pre> <p>small is beautiful :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload