Write a program to compute and display the sum of 3 6 9

Write a program to compute and display the sum of 3 + 6 + 9 + .... + 90. You have to use a for loop in this program. Follow the Engineering problem solving methodology. Problem Statement Input Output Solve by hand Create Algorithm and develop C++ code in Visual Studio Test Code with some data and verify

Solution

Answer:

C++ program :

#include <iostream>

#include <string>
using namespace std;
int main()
{
int i,sum=0;
//for loop
for(i=0;i<=90;i++)
{
if((i%3==0))
{
sum=sum+i;
}
}
cout<<\"Sum of 3+6+9+.......+90 = \"<<sum;

return 0;
}

Output :

Sum of 3+6+9+.......+90 = 1395

 Write a program to compute and display the sum of 3 + 6 + 9 + .... + 90. You have to use a for loop in this program. Follow the Engineering problem solving met

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site