用C++编一程序,先输出一行sun mon tue wed thu fri fri,接着使用右对齐打印出日期,像日历那样
先输出一行sun mon tue wed thu fri fri,再提醒用户输入一个起始日期和终止日期,然后输出结果。
#include<iostream>
#include<iomanip> //要设置域宽,使用setw函数,所以要使用iomanip头文件
using namespace std;
int main(){
int day, stop, i, j, tian;
cout << "Enter the number of day and stop:" << endl;
cin >> day >> stop;
cout << " Sun Mon Tue Wed Thu Fri Sat" << endl;
for (j = 0; j < day; j++) //处理起始日期之前的空格
cout << setw(5) << ' ';
for (i = 1; i <= stop; i++) //将i和终止日期stop进行比较,确定输出结束的时间
{
tian = (i + day) % 7; //保证一行只有七个元素
if (tian == 0)
cout << setw(5) << i << endl; //达到七个元素进行换行
else
cout << setw(5) << i;
}
cout << 'n'; //输出结束时进行换行
system("pause");
return 0;
}
输出结果如下所示:
原文链接: https://www.cnblogs.com/lxt1105/p/5796692.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/239139
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!