Answer to Question #5699 in C++ for Michael Copple

Question #5699
for loop calculate the total of the numbers between two numbers, inclusive
1
Expert's answer
2011-12-20T09:29:52-0500
# include<iostream.h>
# include<conio.h>

int b,a,n,i;

void main(){
cout<<"Enter first number: ";
cin>>a;
cout<<"Enter second number: ";
cin>>b;
n=0;
if (b>=a)
& for (i=a;i<=b;i++) n++;
else
& for (i=a;i>=b;i--) n++;
cout<<"total of numbers between "<<a<<" and "<<b<<" is "<<n<<" (inclusive)\n";
getch();
}

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