当前位置:网站首页>[Supplément linguistique c] déterminer quel jour est demain (date de demain)
[Supplément linguistique c] déterminer quel jour est demain (date de demain)
2022-07-01 16:54:00 【Un roseau pour voler FP】
Un.、Généralités
1.1 Description de la fonction
- Entrez au hasard une date valide,Date du jour suivant la sortie
1.2 Points saillants
- Si la date est le dernier jour du mois?
- Si c'est un février bissextile?
- Si c'est le dernier mois?
1.3 Méthode de réalisation
- Utilisation de structures,Stocke le mois, l'année et le jour dans une variable structurelle
2.、Code
#include<stdio.h>
#include<stdbool.h> //IntroductionboolType
struct date {
//Désignation de la structuredate
int year;
int month;
int day;
};
int numberOfDays(struct date d); //Jours d'un mois
bool isLeap(struct date d); //Année bissextile
int main(int argc, char* const argv[]){
struct date today, tommorow;
printf("Entrez la date(Année Mois Jour):");
scanf(" %i %i %i", &today.year, &today.month, &today.day);
if( today.day != numberOfDays(today) ){
//Comparer les jours, Pour déterminer si le dernier jour
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("Demain, oui. %iAnnée%iMois%iJour.\n",
tommorow.year, tommorow.month, tommorow.day);
return 0;
}
// Déterminer le nombre de jours de ce mois
int numberOfDays(struct date d)
{
int days; // Enregistrer les jours du mois
const int daysPerMonth[12] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Nombre de jours par mois tout au long de l'année
if( d.month == 2 && isLeap(d) )
days = 29; // Février bissextile ,Prends - le.29Oh, mon Dieu.
else
days = daysPerMonth[d.month-1];
return days;
}
//Année bissextile
bool isLeap(struct date d)
{
bool leap = false;
//Année bissextile:Peut être4Diviser mais ne pas être100Effacer,Ou peut être400Effacer
if( (d.year%4 == 0 && d.year%100 != 0) || d.year%400 == 0 )
leap = true;
return leap;
}
边栏推荐
- VMware 虚拟机启动时出现故障:VMware Workstation 与 Hyper-v 不兼容...
- Alibaba cloud, Zhuoyi technology beach grabbing dialogue AI
- Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
- Tutorial on the principle and application of database system (003) -- MySQL installation and configuration: manually configure MySQL (Windows Environment)
- 嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
- C language input / output stream and file operation
- How to restore the system of Sony laptop
- How to use etcd to realize distributed /etc directory
- Chinese diosgenin market forecast and investment strategy report (2022 Edition)
- Basic usage of Frida
猜你喜欢

Installation and use of sqoop

Redis distributed lock

Ring iron pronunciation, dynamic and noiseless, strong and brilliant, magic wave hifiair Bluetooth headset evaluation

Bugku's file contains

How to solve the keyboard key failure of notebook computer

Detailed explanation of activity life cycle and startup mode

sql刷题627. 变更性别

Internet News: "20220222" get together to get licenses; Many products of Jimi have been affirmed by consumers; Starbucks was fined for using expired ingredients in two stores

Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?

Principes et applications du système de base de données (006) - - compilation et installation de MySQL 5.7 (environnement Linux)
随机推荐
Flux d'entrées / sorties et opérations de fichiers en langage C
AI高考志愿填报:大厂神仙打架,考生付费围观
String类
Internet News: "20220222" get together to get licenses; Many products of Jimi have been affirmed by consumers; Starbucks was fined for using expired ingredients in two stores
Bugku's file contains
How to solve the problem that the battery icon of notebook computer does not display
Tutorial on the principle and application of database system (003) -- MySQL installation and configuration: manually configure MySQL (Windows Environment)
sql刷题1050. 合作过至少三次的演员和导演
数据库系统原理与应用教程(006)—— 编译安装 MySQL5.7(Linux 环境)
VMware 虛擬機啟動時出現故障:VMware Workstation 與 Hyper-v 不兼容...
Building blocks for domestic databases, stonedb integrated real-time HTAP database is officially open source!
How to use phpipam to manage IP addresses and subnets
Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
Computed property “xxx“ was assigned to but it has no setter.
【Try to Hack】vulnhub DC4
How to repair the laptop that cannot connect to the wireless network
China nylon 11 industry research and future forecast report (2022 Edition)
Tutorial on the principle and application of database system (005) -- Yum offline installation of MySQL 5.7 (Linux Environment)
【C语言基础】12 字符串
The difference between the lazy mode of singleton mode and the evil mode