I have been working on this code for 1 hour and i keep getting double counting. Please help me to check it.
#include <iostream>
using namespace std;
int main()
{
int n1;
int n2;
cout << "Please enter first number : " ;
cin >> n1;
cout << "Pleae enter second number : " ;
cin >>n2;
for (;n1 >= n2; n1--)
{
cout << n1 << endl;
}
for (;n1 <= n2; n1++)
{
cout << n1 << endl;
}
return 0;
}
This is the result i am getting. I should not be getting last 1 and 2.
Please enter first number : 10
Pleae enter second number : 2
10
9
8
7
6
5
4
3
2
1
2
The counting suppose to stop at 2 not going to second loop at all. It suppose to execute first loop only when n1 >= n2 and print the results but loop still goes to second loop.
#include<iostream>
usingnamespace std;
int main()
{
int n1;
int n2;
cout<<"Enter the first number"<<endl;
cin>>n1;
cout<<"Enter the second number"<<endl;
cin>>n2;
for (int i=n1; i>=n2; i--)
{
cout<< i <<endl;
}
return 0;
}