当前位置:网站首页>[C language] nextday problem
[C language] nextday problem
2022-06-28 14:49:00 【Jia Pu】
Enter a time , Bless The Child , Output the next day
Mainly boundary control , Don't use stupid writing , No technical content , Just a logical test
The notes are perfect , Self understanding
execution environment :Ubuntu18.04 CLion/GCC
WIndows The environment does not need to be modified
Code:
/* Next Day * Be careful : Closely follow the topic , The input format is :xx year xx month xx Japan , Just use this exercise to format strings sscanf() function * As for example 2019 02 25 This format , In this way , The writing is even more boring * Including unnecessary opening up space in the reactor area , At the same time, it also avoids the stack overflow problem caused by users' intentional unlimited input * Learning software testing , It is necessary to consider that nothing is wrong * Postgraduate students can learn more about these functions * * */
#include <stdio.h>
#include <stdlib.h>
int main(void) {
// Definition 13 Length ,0 No. index does not use , Avoid late +1 operation
int monArray[13] = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf(" Enter the date [Format:xx year xx month xx Japan ]:\n");
// Open up space in the reactor area , Stack space Windows Only by default 1M,Linux General default 8M, It can be expanded , I won't go into details here
char *time = malloc(64);
scanf("%s", time);
int year, mon, day;
// The format string is placed in the corresponding variable
sscanf(time, "%d year %d month %d Japan ", &year, &mon, &day);
// Judge after leap year 2 Month array days plus one
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
monArray[2]++;
// month , The day did not exceed the range
if ((mon <= 12 && mon >= 1) && (day <= monArray[mon])) {
// End of month judgment
if (day == monArray[mon]) {
// At the end of the year
if (mon == 12) {
day = 1;
mon = 1;
year++;
}
// Only the end of the moon
else {
day = 1;
mon++;
}
}
// Both month and day are out of range
else {
day++;
}
}
// Month day is out of range , direct return
else {
printf("Data Error\n");
return EXIT_FAILURE;
}
// Calculation successful
printf("Next Day is:%d year %d month %d Japan \n", year, mon, day);
return EXIT_SUCCESS;
}

边栏推荐
- [Zhongyi Xinsheng] 5 SPI interface test TF Card
- New drug discovery methods, AstraZeneca team improves ab initio molecular design through course learning
- 智联招聘基于 Nebula Graph 的推荐实践分享
- 【空间&单细胞组学】第1期:单细胞结合空间转录组研究PDAC肿瘤微环境
- 华泰证券开户有什么后果 怎么办理开户最安全
- Calculator (force buckle)
- 10 key points to effectively improve performance interview
- Leetcode (406) - rebuild the queue based on height
- What are the consequences of opening an account with Huatai Securities? How to open an account is the safest
- 猫狗图像数据集上的深度学习模型性能对比
猜你喜欢

flutter 系列之:flutter 中的 offstage

Mingchuangyou products passed the listing hearing: seeking dual main listing with an annual revenue of 9.1 billion

老板嘱咐了三遍:低调、低调、低调

Tencent cloud international ECS has no network after logging in. How to troubleshoot?

Based on asp Net based document retrieval system

推荐四款可视化工具,解决 99% 的可视化大屏项目!

IonQ联合GE Research证实:量子计算在风险聚合上有巨大潜力

Jingyuan's safe sprint to the Growth Enterprise Market: it plans to raise 400million yuan for investment and Yunyou software is the shareholder

Softing epgate Pb series Gateway - integrates the Profibus bus into the ethernet/ip network

CVPR disputes again: IBM's Chinese draft papers were accused of copying idea, who won the second place in the competition
随机推荐
@ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常
2022 recurrent training question bank and online simulation examination for safety inspection of metal and nonmetal mines (underground mines)
加油站(贪心)
Angers medical sprint scientific innovation board: annual revenue of RMB 300million and proposed fund raising of RMB 770million
Gas station (greedy)
What is the renewal fee for PMP certificate?
RAM ROM FLASH的区别
2022下半年软考考试时间安排已确定!
Softing epGate PB系列网关-可将PROFIBUS总线集成到EtherNet/IP网络
sort
spacy教程(持续更新ing...)
运行近20年,基于Win 98的火星探测器软件迎来首次升级
等保备案主体是谁?在当地网安进行备案是吗?
鸟类飞行状态下穿戴式神经信号与行为数据检测记录系统的技术难点总结
【数字IC精品文章收录】近500篇文章|学习路线|基础知识|接口|总线|脚本语言|芯片求职|安全|EDA|工具|低功耗设计|Verilog|低功耗|STA|设计|验证|FPGA|架构|AMBA|书籍|
力扣解法汇总522-最长特殊序列 II
PMP真的有用吗?
考了这个PMP证书到底有什么好处?
Leetcode (665) -- non decreasing column
PMP认证证书的续证费用是多少?