当前位置:网站首页>【C语言补充】判断明天是哪一天(明天的日期)
【C语言补充】判断明天是哪一天(明天的日期)
2022-07-01 16:28:00 【一苇以航fp】
一、概述
1.1 功能介绍
- 随机输入一个有效日期,输出第二天的日期
1.2 重点
- 该日期是否是某月最后一天?
- 是否是闰二月?
- 是否是最后一个月?
1.3 实现方法
- 使用结构体,将年月日存储在一个结构变量中
二、代码
#include<stdio.h>
#include<stdbool.h> //引入bool类型
struct date {
//结构标号date
int year;
int month;
int day;
};
int numberOfDays(struct date d); //某月天数
bool isLeap(struct date d); //判断闰年
int main(int argc, char* const argv[]){
struct date today, tommorow;
printf("输入日期(年 月 日):");
scanf(" %i %i %i", &today.year, &today.month, &today.day);
if( today.day != numberOfDays(today) ){
//比较天数, 判断是否最后一天
tommorow.day = 1;
tommorow.month = today.month + 1;
tommorow.year = today.year;
}
else if( today.month == 12 ){
tommorow.day = 1;
tommorow.month =1;
tommorow.year = today.year + 1;
}
else {
tommorow.day = today.day + 1;
tommorow.month = today.month;
tommorow.year = today.year;
}
printf("明天是 %i年%i月%i日.\n",
tommorow.year, tommorow.month, tommorow.day);
return 0;
}
//判断本月天数
int numberOfDays(struct date d)
{
int days; //记录本月天数
const int daysPerMonth[12] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //全年各月天数
if( d.month == 2 && isLeap(d) )
days = 29; //闰二月,取29天
else
days = daysPerMonth[d.month-1];
return days;
}
//判断闰年
bool isLeap(struct date d)
{
bool leap = false;
//闰年:能被4整除但不能被100整除,或能被400整除
if( (d.year%4 == 0 && d.year%100 != 0) || d.year%400 == 0 )
leap = true;
return leap;
}
边栏推荐
- 复杂度相关OJ题(LeetCode、C语言、复杂度、消失的数字、旋转数组)
- Installation and use of sqoop
- SQL question brushing 584 Looking for user references
- How to solve the keyboard key failure of notebook computer
- Tutorial on the principle and application of database system (001) -- MySQL installation and configuration: installation of MySQL software (Windows Environment)
- Redis Distributed Lock
- The difference between the lazy mode of singleton mode and the evil mode
- 机器学习11-聚类,孤立点判别
- Authentication processing in interface testing framework
- 巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
猜你喜欢

模板引擎Velocity 基礎

【PyG】文档总结以及项目经验(持续更新

【直播预约】数据库OBCP认证全面升级公开课

免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!

数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)

Basic use of MySQL

C語言輸入/輸出流和文件操作
![[pyg] document summary and project experience (continuously updated](/img/b4/75da8c3e657069be4e3e3bfd5b2dc0.png)
[pyg] document summary and project experience (continuously updated

Défaillance lors du démarrage de la machine virtuelle VMware: le poste de travail VMware n'est pas compatible avec hyper - V...

数据库系统原理与应用教程(006)—— 编译安装 MySQL5.7(Linux 环境)
随机推荐
巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
模板引擎Velocity 基礎
Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
sql刷题627. 变更性别
Rhcsa Road
判断一棵二叉树是否为平衡二叉树
Detailed explanation of activity life cycle and startup mode
Zabbix2.2 monitoring system and application log monitoring alarm
为国产数据库添砖加瓦,StoneDB 一体化实时 HTAP 数据库正式开源!
独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
Template Engine Velocity Foundation
Leetcode 77 combination -- backtracking method
Judge whether a binary tree is a balanced binary tree
Tutorial on the principle and application of database system (003) -- MySQL installation and configuration: manually configure MySQL (Windows Environment)
Sweden announced its decision to exclude Huawei 5g equipment, but Huawei has successfully found a new way out
Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
Authentication processing in interface testing framework
Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
Preliminary study on golang crawler framework
Basic use of MySQL