当前位置:网站首页>C语言刷题 | 判断某年是否只闰年(12)
C语言刷题 | 判断某年是否只闰年(12)
2022-06-22 09:10:00 【C语言小火车】
例12: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语言的同时加以总结与思考,才能对编程有更系统和深入地了解,学到的知识才真正能为自己所用。
边栏推荐
- 10 decoration mode
- kali木马入侵win7系统
- pip3 install xxx报错:Command 'lsb_release -a' returned non-zero exit status 1.
- PIP3 install XXX reports an error: command'lsb_ release -a' returned non-zero exit status 1.
- 滴滴二面总结
- 断言assert()
- 800+ PHP grammar and words are proficient only after you have used them
- container_of
- Wireless routing attack and WiFi password cracking practice [penetration technology]
- Solidity from introduction to practice (6)
猜你喜欢

医疗信息管理系统数据库--MySQL

Interview shock 59: can there be multiple auto increment columns in a table?

10.file/io stream -bite

Flask blog practice - realize article management

DOM编程

Solidity from introduction to practice (V)

Flask blog practice - realize the classified management of blogs

我的第一个Go程序

Message Oriented Middleware (message queue)

Fanatical NFT, foam or tuyere?
随机推荐
国外十款免费开源PHP网店程序介绍
Luogu p5406 [thupc2019] find tree
Solidity from introduction to practice (II)
模板引擎,让交互变得优雅
09 combination mode
Why can MySQL indexes improve query efficiency so much?
pip3 install xxx报错:Command 'lsb_release -a' returned non-zero exit status 1.
scnprintf和snprintf的区别
Manually mining XSS vulnerabilities
Use record of rabbit nest
PHP login registration page
医疗信息管理系统数据库--MySQL
[target detection] | detection error mechanism why object detectors fail: investigating the influence of the dataset
【uni-app】实战总结(含多端打包)
Luogu p4292 [wc2010] reconstruction plan
嵌入式开发专业术语概念汇总
Solidity from introduction to practice (6)
My first go program
景联文科技:机器学习AI数据集产品汇总(三)
The version problem caused "unable to locate the program input point openssl\u sk\new\u reserve in the dynamic link library c:\users... \libssl-1\u 1-x64.dll"