当前位置:网站首页>[C language] PTA 7-91 output leap year
[C language] PTA 7-91 output leap year
2022-07-29 04:29:00 【LastWhisperw】
Output 21 All leap year years in the century ending in a certain year . Be careful : The criterion of leap year is that the year can be 4 Divide but not be 100 to be divisible by 、 Or can be 400 to be divisible by .
Input format :
Enter... On one line 21 One of the closing years of the century .
Output format :
Output all leap years that meet the conditions line by line , That is, one line per year . Input if not 21 The year of the century is exported "Invalid year!". If there are no leap years , The output “None”.
sample input 1:
2048
No blank lines at the end
sample output 1:
2004
2008
2012
2016
2020
2024
2028
2032
2036
2040
2044
2048
No blank lines at the end
sample input 2:
2000
sample output 2:
Invalid year!
Ideas : It starts with a branch statement :1, Illegal input ( be not in 21 Within the scope of the century, it does not belong to 2001-2100);2、 There is no leap year in the interval ( That is, the number of years entered is less than 2004),3、 There are leap years in the interval
For the input with leap years in the interval , Use a loop to output all leap years . Here, each cycle directly makes i=i+4, Not divisible 100 Words ( In fact, it can divide 100 There is only 2100 year ) It's leap year .
#include<stdio.h>
int main(){
int year;
scanf("%d",&year);
if( year<2001 || year>2100){
printf("Invalid year!");
}else if(year<2004){
printf("None");
}
else{
int i;
for(i=2004;i<=year;i=i+4){
if(i%100==0){
continue;
}
if(year-i<4)
{printf("%d",i);
}
else
{printf("%d\n",i);
}
}
}
return 0;
}
边栏推荐
- 15.federation
- 不会就坚持66天吧 权重生成随机数
- Exception handling: pyemd or pyemd not found
- [express connection to MySQL database]
- Cad2020 introductory learning (2021.4.13)
- Leftmost prefix principle of index
- Don't stick to it for 68 days. Baboons eat bananas
- 9. Delay queue
- Class starts! See how smardaten decomposes complex business scenarios
- 10.回退消息
猜你喜欢
Definition and implementation of stack and queue (detailed)
String, array, generalized table (detailed)
用 ZEGO Avatar 做一个虚拟人|虚拟主播直播解决方案
通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值
Post export data, return
不会就坚持66天吧 权重生成随机数
Understand the Internet giant [the war between China and Taiwan] and the development thinking of China and Taiwan
顺序表和链表
Don't insist on 66 days. Weight generates random numbers
10.回退消息
随机推荐
Pix2.4.8 from start to installation (2021.4.4)
Update learning materials daily
使用容器部署Jenkins
Pytorch GPU and CPU models load each other
VScode 一键编译和调试
i++与++i详解
读懂 互联网巨头 【中台之战】 以及 中台 发展思维
论pyscript使用感想(实现office预览)
Machine vision Series 1: Visual Studio 2019 dynamic link library DLL establishment
不会就坚持58天吧 实现前缀树
What is the use of meta-info?
Won't you just stick to 69 days? Merge range
Machine vision series 3:vs2019 opencv environment configuration
visio画网格
Record of problems encountered in ROS learning
Common components of solder pad (2021.4.6)
Multi card training in pytorch
TypeError: Cannot read properties of undefined (reading ‘then‘)
Make a virtual human with zego avatar | virtual anchor live broadcast solution
Record the Niua packaging deployment project