title: Sum of a series using a for loop in C++
body: <p>I want to compute the sum of the following series:</p>
  
  <pre><code>5 + 8 + 11 + .... + 50
  </code></pre>
  
  <p>I wish to use a for loop to print the above series and the sum of the series. I have written the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      int i, sum = 0, n = 50;
      cout &lt;&lt; "\n\n THE SERIES IS UNDER : \n\n\n";
      i = 2;
      while(i &lt;= n)
      {
          sum = sum + i;
          if (i == 2)
              cout &lt;&lt; i;
          else
              cout &lt;&lt; " + "&lt;&lt; i;
          i = i + 3;
      }
      cout &lt;&lt; "\n\n\n THE SUMMATION IS "&lt;&lt; sum;
      return 0;
  }
  </code></pre>