Answer to Question #311000 in C++ for Talimul

Question #311000

Repeat Prob. 6.45 calculating the sum of every nth integer, beginning with the value assigned to nstart (i.e., for

i= nstart, nstart + n, nstart + 2*n, nstart + 3*n, etc.).


1
Expert's answer
2022-03-13T15:11:12-0400
#include <iostream>
using namespace std;


int main() {
    int nstart, nend, n;


    cout << "Enter nstart: ";
    cin >> nstart;
    cout << "Enter nend: ";
    cin >> nend;
    cout << "Enter n: ";
    cin >> n;


    int sum=0;
    for (int i=nstart; i<=nend; i+=n) {
        sum += i;
    }


    cout << "The sum is " << sum;


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment