当前位置:网站首页>[C language supplement] judge which day tomorrow is (tomorrow's date)
[C language supplement] judge which day tomorrow is (tomorrow's date)
2022-07-01 16:54:00 【One reed to sail FP】
One 、 summary
1.1 Function is introduced
- Enter a valid date randomly , Output the date of the next day
1.2 a key
- Whether this date is the last day of a month ?
- Is it leap February ?
- Is it the last month ?
1.3 Implementation method
- Use structure , Store the month, year and day in a structural variable
Two 、 Code
#include<stdio.h>
#include<stdbool.h> // introduce bool type
struct date {
// Structure label date
int year;
int month;
int day;
};
int numberOfDays(struct date d); // Number of days in a month
bool isLeap(struct date d); // Judgement of leap year
int main(int argc, char* const argv[]){
struct date today, tommorow;
printf(" Enter the date ( year month Japan ):");
scanf(" %i %i %i", &today.year, &today.month, &today.day);
if( today.day != numberOfDays(today) ){
// Comparison days , Determine whether the last day
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(" Tomorrow is %i year %i month %i Japan .\n",
tommorow.year, tommorow.month, tommorow.day);
return 0;
}
// Judge the number of days in this month
int numberOfDays(struct date d)
{
int days; // Record the number of days in this month
const int daysPerMonth[12] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // The number of days in each month of the year
if( d.month == 2 && isLeap(d) )
days = 29; // Leap February , take 29 God
else
days = daysPerMonth[d.month-1];
return days;
}
// Judgement of leap year
bool isLeap(struct date d)
{
bool leap = false;
// Leap year : Can be 4 Divide but not be 100 to be divisible by , Or can be 400 to be divisible by
if( (d.year%4 == 0 && d.year%100 != 0) || d.year%400 == 0 )
leap = true;
return leap;
}
边栏推荐
- 软件工程导论——第六章——详细设计
- Chinese diosgenin market forecast and investment strategy report (2022 Edition)
- Computed property “xxx“ was assigned to but it has no setter.
- 數據庫系統原理與應用教程(006)—— 編譯安裝 MySQL5.7(Linux 環境)
- What are the differences between PHP and DW
- Rhcsa Road
- Stegano in the world of attack and defense
- 博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
- 判断一棵二叉树是否为平衡二叉树
- SQL question brushing 584 Looking for user references
猜你喜欢

巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...

sql刷题627. 变更性别

Buuctf gold III

Redis 分布式鎖

Machine learning 11 clustering, outlier discrimination

模板引擎Velocity 基础

SystemVerilog structure (II)

Rhcsa Road

數據庫系統原理與應用教程(006)—— 編譯安裝 MySQL5.7(Linux 環境)

How to use etcd to realize distributed /etc directory
随机推荐
Rhcsa Road
Preliminary study on golang crawler framework
【直播预约】数据库OBCP认证全面升级公开课
How to solve the problem that the battery icon of notebook computer does not display
数据库系统原理与应用教程(004)—— MySQL 安装与配置:重置 MySQL 登录密码(windows 环境)
[live broadcast appointment] database obcp certification comprehensive upgrade open class
AI高考志愿填报:大厂神仙打架,考生付费围观
Computed property “xxx“ was assigned to but it has no setter.
想做软件测试的女孩子看这里
判断二叉树是否为二叉搜索树
[jetsonnano] [tutorial] [introductory series] [III] build tensorflow environment
[nodemon] app crashed - waiting for file changes before starting... resolvent
剑指 Offer II 105. 岛屿的最大面积
Bugku's file contains
Buuctf gold III
Installation and use of sqoop
博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
Building blocks for domestic databases, stonedb integrated real-time HTAP database is officially open source!
How to solve the keyboard key failure of notebook computer
China carbon disulfide industry research and investment strategy report (2022 Edition)