Answer to Question #16471 in C++ for Michael Rothermel

Question #16471
& Write a general summation program that allows the user to determine where it will begin and end, and what the increment shall be.
1
Expert's answer
2012-10-17T09:39:15-0400
#include<iostream>
using namespace std;

int b, e, i;

int sum(int b, int e, int i){
int res=0;
for (int k=b; k<=e; k++) res+=i;
return res;
}

void main(){
cout<<"enter the begin: ";
cin>>b;
cout<<"enter the end: ";
cin>>e;
cout<<"enter the increment: ";
cin>>i;

cout<<"sum = "<<sum(b,e,i)<<"\n";
system("PAUSE");
}

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

LATEST TUTORIALS
APPROVED BY CLIENTS