当前位置:网站首页>[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;
}
边栏推荐
- AI college entrance examination volunteer filling: the gods of Dachang fight, and candidates pay to watch
- sql刷题1050. 合作过至少三次的演员和导演
- EndeavourOS移动硬盘安装
- Transition technology from IPv4 to IPv6
- Rhcsa Road
- 数据库系统原理与应用教程(004)—— MySQL 安装与配置:重置 MySQL 登录密码(windows 环境)
- Is it reliable to open an account on flush with mobile phones? Is there any potential safety hazard
- Leetcode 77 combination -- backtracking method
- SystemVerilog structure (II)
- 剑指 Offer II 105. 岛屿的最大面积
猜你喜欢
Redis 分布式鎖
Hi Fun Summer, play SQL planner with starrocks!
[live broadcast appointment] database obcp certification comprehensive upgrade open class
Detailed explanation of activity life cycle and startup mode
Bugku's file contains
Tutorial on the principle and application of database system (001) -- MySQL installation and configuration: installation of MySQL software (Windows Environment)
Soft test network engineer full truth simulation question (including answer and analysis)
想做软件测试的女孩子看这里
Activity的生命周期和启动模式详解
How to use etcd to realize distributed /etc directory
随机推荐
软件工程导论——第六章——详细设计
How to use etcd to realize distributed /etc directory
Building blocks for domestic databases, stonedb integrated real-time HTAP database is officially open source!
Jojogan practice
Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
Soft test network engineer full truth simulation question (including answer and analysis)
Red team Chapter 10: ColdFusion the difficult process of deserializing WAF to exp to get the target
The difference between the lazy mode of singleton mode and the evil mode
Transition technology from IPv4 to IPv6
UML tourism management system "suggestions collection"
VMware 虚拟机启动时出现故障:VMware Workstation 与 Hyper-v 不兼容...
Origin2018 installation and use (sorting)
Stegano in the world of attack and defense
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
[nodemon] app crashed - waiting for file changes before starting... resolvent
阿里云、追一科技抢滩对话式AI
Are you still using charged document management tools? I have a better choice! Completely free
【flask入门系列】Cookie与Session
SQL question brushing 586 Customers with the most orders
Is the securities account given by the head teacher of goucai school safe? Can I open an account?