当前位置:网站首页>[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;
}
边栏推荐
猜你喜欢

How to use etcd to realize distributed /etc directory

Jojogan practice

今天14:00 | 港大、北航、耶鲁、清华、加大等15位ICLR一作讲者精彩继续!

How to solve the problem that the battery icon of notebook computer does not display

C语言输入/输出流和文件操作

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

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

Basic use of MySQL

软件工程导论——第六章——详细设计

Introduction to software engineering - Chapter 6 - detailed design
随机推荐
VMware 虛擬機啟動時出現故障:VMware Workstation 與 Hyper-v 不兼容...
Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
Tutorial on principles and applications of database system (004) -- MySQL installation and configuration: resetting MySQL login password (Windows Environment)
【PyG】文档总结以及项目经验(持续更新
Please, stop painting star! This has nothing to do with patriotism!
FPN network details
Sword finger offer II 015 All modifiers in the string
Tutorial on principles and applications of database system (006) -- compiling and installing MySQL 5.7 (Linux Environment)
判断链表是否是回文链表
VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
How to repair the laptop that cannot connect to the wireless network
Research and investment strategy report of neutral protease industry in China (2022 Edition)
SQL question brushing 584 Looking for user references
Machine learning 11 clustering, outlier discrimination
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
How to restore the system with one click on Lenovo laptop
Rhcsa Road
Bugku's file contains
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
String class