title: Find all prime factors of a given number
body: <p>I want to find <a href="https://en.wikipedia.org/wiki/Integer_factorization" rel="nofollow noreferrer">all prime factors of a number</a>, for example <code>8: 2   2   2</code> or <code>12: 2   2   3</code>.</p>
  
  <p>So I write this code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
      int a, triangularNum, n;
  
      scanf("%d", &amp;triangularNum);
  
      for (a = 2; a &lt;= n; ++a) {
          while (n % a == 0) {
              n = triangularNum;
              printf("%d\t", a);
              n = n / a;
          }
      }
  }
  </code></pre>
  
  <p>But when it has a factor with power > 1, it only prints that factor many times.</p>