当前位置:网站首页>[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:
2048No blank lines at the end
sample output 1:
2004
2008
2012
2016
2020
2024
2028
2032
2036
2040
2044
2048No blank lines at the end
sample input 2:
2000sample 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;
} 边栏推荐
- MySQL - 聚簇索引和辅助索引
- Machine vision Series 2: vs DLL debugging
- Can you really write restful API?
- MySQL - clustered index and secondary index
- Understand the Internet giant [the war between China and Taiwan] and the development thinking of China and Taiwan
- VScode 一键编译和调试
- LeetCode_ Stack topics
- Redux quick start
- kotlin的List,Map,Set等集合类不指定类型
- Leftmost prefix principle of index
猜你喜欢
随机推荐
[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)
Target detection learning process
14.haproxy+keepalived负载均衡和高可用
12. Priority queue and inert queue
Webrtc realizes simple audio and video call function
10.回退消息
Differences and principles of bio, NiO and AIO
C语言:联合体知识点总结
论pyscript使用感想(实现office预览)
不会就坚持66天吧 权重生成随机数
Deploy Jenkins using containers
Pix2.4.8 from start to installation (2021.4.4)
Locker 2022.1.1
异常解决:cococaption包出现找不到edu.stanford.nlp.semgraph.semgrex.SemgrexPattern错误
Pytoch automatic mixing accuracy (AMP) training
WebRTC实现简单音视频通话功能
Down sampling and up sampling
On the use of pyscript (realizing office preview)
15.federation
The pit I walked through: the first ad Sketchpad









