That's because you are recalculating too many values. (ie: 6 need 5 and 4, but 5 also calls 4 ).
You could improve a lot if you store the values that you already calculate (dynamic programming)
int main()
{
int count;
int num1;
int num2;
int sum;
sum = 0;
//count<num1; <-- count never initialize, what is with the < ?? dno't quite understand the reason behind this
cout << "enter first integer :";
cin >> num1;
cout << "enter second integer : ";
cin >> num2;
//while ( count< num1,count <= num2) <- are u trying to achieve calculations over calculations?
//{
cout << "count << endl";
sum = num1 + num2;
//}
cout << "Sum of first & second number = " << sum;
return 0;
}
Ok...but i run the program but its not showing the sum of integer between two numbers...please edit the control statement..i am sure thats where my error is
open create your own thread topic instead of supersede nanochan1.
to your problem:
1 2 3 4 5 6
if(num1 > num2) // now it doesn't matter which is the least value
std::swap(num1, num2);
for(int i = num1; i <= num2; ++i) // '<=' instead of '<' (my fault)
{
sum += i;
}
compute the sum of all the integer numbers in between these two numbers.