using four step development method, write, compile and run a c++ program to calc
ID: 3836337 • Letter: U
Question
using four step development method, write, compile and run a c++ program to calculate the sum of the even integers from 1-50 [30 points] PROGRAMMING PROBLEM 1: using four step development method, compile, and run ac program to calculate the design, write, sum of the even integers from 1 to 50. Here is the formula for calculating such a sum for an progression series: sum E n is the number of integers to be added, a is the first number in the series, d is the difference between each number. Make sure that the division by 2 in the formula is implemented properly in your program. SOLUTION: [5 points] Step 1-Analyze the Problem There are three inputs to the program: a n, d. Data types: There is only one output from the program, namely, sum. Data type: [5 points] Step 2 Find a Solution The algorithm is specified. However, we need to make sure that the division by 2 is not done as an integer division. So the modified algorithm will read as followsExplanation / Answer
Source code:
#include<stdio.h>
#include <iostream>
using namespace std;
int main()
{
int number; int min,max; long sum =0;
cout << "Enter the minimum range: ";
cin >> min;
cout << "Enter the maximum range: ";
cin >> max;
for(number = min;number <= max; number++) if(number % 2 ==0)
sum = sum + number;
cout << "Sum of even numbers in given range is: " << sum;
return 0;
}
Output:
Enter minimum range:1
Enter maximum range:4
Sum of even numbers in given range is :6
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.