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

Question #5699

for loop calculate the total of the numbers between two numbers, inclusive

Expert's answer

# 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();

}

# 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 orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment