title: How to speed up printf in C
body: <p>I have a task to print all the prime numbers between 1 and 1000000 in class and the fastest 10 programs get extra marks. The main problem is the time it takes for the prime numbers to be printed to the console.</p>
  
  <p>Basically using the Sieve of Eratosthenes I produce an array with only boolean values in it. The boolean value <code>Numbers[i]</code> is true if <code>i+2</code> is a prime number.</p>
  
  <pre><code>for(i = 0; i &lt;= n - 2; ++i)
     if (Numbers[i]) // True if the number is prime
          printf("%d\n", i+2);
  </code></pre>
  
  <p>Printf seems to be really slow as the program can generate the list of primes in about 0.035 s but then takes a further 11 seconds to print the list. Is there anyway I can speed this up, thanks.</p>