C++:显示每年的各月份第一天是星期几

该C++程序要求用户输入一年的年份和该年的第一天是星期几,然后逐月显示这一年内每个月的第一天是星期几。程序通过计算每个月份的天数和星期的循环,实现了这一功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编写一个程序,提示用户输入一个年份以及这一年中第一天是星期几,

然后,输出每个月的第一天是星期几。

#include <iostream>
using namespace std;

int main()
{
  cout << "Enter a year: ";
  int year;
  cin >> year;

  cout << "Enter the first day of the year: ";
  int firstDay;
  cin >> firstDay;

  int numberOfDaysInMonth = 0;

  // Display calendar for each month
  for (int month = 1; month <= 12; month++)
  {
    // Display Calendar title
    switch (month)
    {
      case 1:
        cout << "January 1, " << year << " is ";
        numberOfDaysInMonth = 31;
      break;
      case 2:
  &nbs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值