#include <iostream>
using namespace std;
int main()
{
int n1,n2 = 0;
cout << "Input two numbers please:"<<endl;
cin>> n1 >> n2;
if (n1<n2)
{
cout << "The numbers between "<<n1<<" and "<<n2<<" are: ";
int n = 0;
int num = n2 - n1 -1;
while( n < num )
{
++n1;
cout <<" "<< n1;
++n;
}
}
else if(n1>n2)
{
cout << "The numbers between "<<n2<<" and "<<n1<<" are: ";
int n = 0;
int num = n1 -n2 -1; //为什么while(n < n1 - n2 -1)时不能打印出正确的结果,优先级的问题?
while(n< num )
{
--n1;
cout <<" "<< n1;
++n;
}
}
return 0;
}
练习1.11:打印出两个整数之间的所有数
最新推荐文章于 2024-10-18 13:33:49 发布