您的位置:首页 > 其它

练习1.11:打印出两个整数之间的所有数

2016-10-02 01:32 288 查看
#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;
}
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐