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