title: Counting prime numbers in C++
body: <p>How do I count all the "prime" numbers instead of displaying them?</p>
  
  <p>Example:</p>
  
  <pre><code>cout &lt;&lt; "there are 125 prime numbers";
  </code></pre>
  
  <p>I'm using the number 1000 because I want to find out how many prime numbers it has.</p>
  
  <p>I don't want to display the found prime numbers but I want to know how many have been found.</p>
  
  <pre><code>#include &lt;iostream&gt; 
  #include &lt;iomanip&gt; 
  #include &lt;string&gt;
  #include &lt;sstream&gt; 
  #include &lt;fstream&gt; 
  #include &lt;math.h&gt; 
  #include &lt;stdio.h&gt;
  
  using namespace std;
  
  int main()
  {
      for (int a=2 ; a &lt; 1000 ; a++)
      {
          bool prime = true;
  
          for(int c=2 ; c*c &lt;= a ; c++)
          {
              if(a % c == 0)
              {
                  prime = false;
                  break;
              }
          }
  
          if(prime) cout &lt;&lt; a &lt;&lt; " ";
      }
  
      return 0;
  }
  </code></pre>