输入两个整数,打印出这两个整数所指定范围内的所有整数,用for循环解决
代码:
#include<iostream>
int main()
{
std::cout << "请输入两个数:";
std::cout << std::endl;
int a, b,c;
std::cin >> a >> b;
if (a > b)
for (c = a+1; a >= b; a-- ) {
--c;
std::cout << c << " ";
}
else
for (c = a-1; a <= b; a++ ) {
++c;
std::cout << c << " ";
}
std::cout << std::endl;
return 0;
}