<分区>
在 for
循环中使用 %
得到一个 saw 函数,例如使用 5 打印 2 个周期的周期看起来像这样:
for(auto i = 0; i < 5 * 2; ++i) cout << i % 5 << endl;
结果:
0
1
2
3
4
0
1
2
3
4
我想要一个函数返回三角波,所以对于某些函数foo
:
for(auto i = 0; i < 5 * 2; ++i) cout << foo(i, 5) << endl;
会导致:
0
1
2
1
0
0
1
2
1
0
有没有这样的功能,还是需要自己想出一个?