当前位置:网站首页>C语言刷题 | 判断某年是否只闰年(15)
C语言刷题 | 判断某年是否只闰年(15)
2022-06-22 09:10:00 【C语言小火车】
目录
例15:C语言实现判断某一年是否是闰年。
解题思路:
首先要想出如果这一年是闰年的条件,闰年是公历中的名词,分为普通闰年和世纪闰年,普通闰年:公历年份是4的倍数的,且不是100的倍数,为普通闰年;世纪闰年:公历年份是整百数的,必须是400的倍数才是世纪闰年。
源代码演示:
#include<stdio.h>//头文件
int main()//主函数
{
int year;//定义整型变量
printf("随意输入一年:");//提示语句
scanf("%d",&year);//键盘输入年份
if((year%4==0 && year%100!=0)||year%400==0)//判断闰年的条件
{
printf("%d是闰年\n",year);
}
else
{
printf("%d不是闰年\n",year);
}
return 0; //函数返回值为0
}
编译结果:
随意输入一年:2000
2000是闰年
--------------------------------
Process exited after 3.921 seconds with return value 0
请按任意键继续. . .我们常说“学而不思则罔”,我们只有在学习C语言的同时加以总结与思考,才能对编程有更系统和深入地了解,学到的知识才真正能为自己所用。
边栏推荐
- OpenCV每日函数 直方图相关(3)
- Matlab内数据及数据类型转换
- 文件小能手---multer
- Epidemic situation of novel coronavirus
- Ten ways to write ABC by three different threads [concurrent programming JUC]
- Off line identification of least square method
- 【node】脚手架搭建服务器,完成token验证
- Thread. Source code analysis of start() method
- Report: in the technical field, men are more likely to get job interviews
- 【Tensorboard】所有雷区都踩,一文解决你所有问题
猜你喜欢

Flask blog practice - realize article management

Instanceinforeplicator class of Eureka (service registration assistant)

threejs实现简单全景看房demo

关于EasyPoi导入Excel文件二级表头数据时@ExcelEntity实体类里的第一列数据为null的这档事

性能优化专题

模板引擎,让交互变得优雅

Thread. Source code analysis of start() method
![[target detection] | detection error mechanism why object detectors fail: investigating the influence of the dataset](/img/d2/101c8ef5dac517718bbe44ee4fd607.png)
[target detection] | detection error mechanism why object detectors fail: investigating the influence of the dataset

18 intermediary model

【自适应控制】最小二乘法离线辨识
随机推荐
开发报错记录
STM32在线升级BootLoader跳转APP时死机问题
Pytorch oserror: DLL load failed: problem solving
12 yuan sharing mode
Shell中的单中括号和双中括号的区别
The dream of "getting rich overnight" is broken. Beware of virtual currency investment scams!!!
Monaco editor format JSON, SQL
CF1267G Game Relics
pip3 install xxx报错:Command 'lsb_release -a' returned non-zero exit status 1.
Flask blog practice - realize the article list page and details page
项目优化+上线(掌握了么?)
PHP de duplication and arrange complete small functions in descending order of length
Flask blog practice - form validation using wtforms
Why can MySQL indexes improve query efficiency so much?
Guide to quick withdrawal and withdrawal of us and Hong Kong stocks
Classification of SQL language
[qnx hypervisor 2.2 user manual]5.6 close guest
Off line identification of least square method
Php+sql get the field name and detailed attributes of MySQL data table
【路径规划】辅助点与多段贝塞尔平滑RRT