练习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; }
相关文章推荐
- 1.编写一个简单的C语言程序:根据输入的两个整数求平均值并且在终端输出,通过gcc编译器得到它的汇编程序文件。 2.编写一个C语言程序:打印输出所有“水仙花数”,用gdb调试程序(给出步骤)。所谓“
- 查找介于n1与n2(0<n1<n2<32768)之间所有满足下列条件的整数: (1)该数的十进制表示中有且仅有两个相同的数字位; (2)该数是素数。
- 求两个整数之间的所有素数
- C#l练习(用方法来实现:①判断一个给定的整数是否为“质数”。②计算1-100之间的所有质数(素数)的和
- 输入两个整数值n和m,求出整数1到n之间的和为m的所有组合
- 输入两个整数值n和m,求出整数1到n之间的和为m的所有组合
- Android编程实现计算两个日期之间天数并打印所有日期的方法
- C语言编程练习——查找介于n1与n2(0<n1<n2<32768)之间所有满足下列条件的整数:
- java 打印出两个IP之间的所有IP值
- 算法15:打印中两个整数范围内的所有素数,例如:(12, 15) ->13
- 两个整数之间能被3整除的所有数之和
- C语言从键盘输入两个数,求两个数之间素数的个数并打印所有素数(定义法)
- [Java]java4android学习笔记(第11集) ---练习一:打印出100-200之间的所有素数
- java循环练习:手动输入两个数字m和n,运算求出m~n之间所有偶数的和
- 查找介于n1与n2(0<n1<n2<32768)之间所有满足下列条件的整数: (1)该数的十进制表示中有且仅有两个相同的数字位; (2)该数是素数
- 查找介于n1与n2(0<n1<n2<32768)之间所有满足下列条件的整数: (1)该数的十进制表示中有且仅有两个相同的数字位; (2)该数是素数。
- C#l练习(用方法来实现:分别计算1-100之间的所有整数的和和奇数的和)
- 我们认为2是第一个素数,3是第二个素数,5是第三个素数,依次类推。 现在,给定两个整数n和m,0<n<=m<=200,你的程序要计算第n个素数到第m个素数之间所有的素数的和,包括第n个素数和第m个素数
- iOS 算法面试题(打印2-100之间的素数、求两个整数的最大公约数、查找字符串的位置)~demo
- 输入两个整数值n和m,求出整数1到n之间的和为m的所有组合