作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 C++ 的新手,所以昨晚我想到了一些事情。我想打印出 1-100 的数字,但每行 10 个数字。我知道下面的代码是错误的,因为它只是垂直打印 1-100。如果有人能阐明我的问题,将不胜感激。感谢阅读:)
#include <iostream>
using namespace std;
int main() {
for(int x = 1; x <= 100; x++) {
cout << x << endl;
}
}
最佳答案
所以你想打印 10 个数字,然后是一个回车符,然后是 10 个数字,然后是一个回车符,依此类推,对吗?
如果是这样,怎么样:
for(int x = 1; x <= 100; x++) {
cout << x << " ";
if ((x%10)==0) cout << endl;
}
关于c++ - 简单的for循环我想不通,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32877619/
我是一名优秀的程序员,十分优秀!