C++ 倒序输出数字 1 到 10 的代码示例
以下是使用 C++ 编写的程序,它将倒序输出 1 到 10 个数字:
#include <iostream>
using namespace std;
int main() {
for (int i = 10; i >= 1; i--) {
cout << i << endl;
}
return 0;
}
这段代码使用了'for'循环,从整数 10 开始,每次循环递减 1,直到循环变量'i'的值为 1 为止。在每次循环中,使用'cout'语句输出当前的'i'值,并在之后换行。执行此代码将倒序输出 1 到 10 的数字。
原文地址: https://www.cveoy.top/t/topic/AQt 著作权归作者所有。请勿转载和采集!