如何在c ++中围绕日历循环数字?

时间:2015-05-30 02:57:38

标签: c++builder

我已经在这个项目上工作了几个小时,并且无法找到如何使数字在星期六达到之后循环。他们要么把它传递到右边,要么我添加和终止;他们上下起伏。

// This is how my output looks like (except they curve around they just go forever to the right:

Number of days: 31
Offset: 0
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

1 个答案:

答案 0 :(得分:0)

这是什么意思?

#include <iostream>

using namespace std;

int main()
{
    int i;
    for (i=1; i<=31; i++) {
        cout << ((i<10) ? " " : "") << i << " ";
        if (i%7==0) cout << endl; 
    }
    return 0;
}

输出:

 1  2  3  4  5  6  7                                                                                                                                                                                                                  
 8  9 10 11 12 13 14                                                                                                                                                                                                                  
15 16 17 18 19 20 21                                                                                                                                                                                                                  
22 23 24 25 26 27 28                                                                                                                                                                                                            
29 30 31

%符号是模数运算符。它给出了除法的余数。所以每7天除以7将剩下零。这就是你如何检查换行符的位置。