程序检查给定年份是否为C中的leap年
year年有366天,而正常年份有365天,任务是通过程序检查给定年份是否为a年。
它的逻辑可以通过检查是否将Year除以400或4,但是如果数字未除以正常年份而得到的任何数字。
示例
Input-: year=2000 Output-: 2000 is a Leap Year Input-: year=101 Output-: 101 is not a Leap year
算法
Start
Step 1 -> declare function 布尔检查年份是否为a年
bool check(int year)
IF year % 400 = 0 || year%4 = 0
return true
End
Else
return false
End
Step 2 -> In main() Declare variable as int year = 2000
Set check(year)? printf("%d is a Leap Year",year): printf("%d is not a Leap Year",year)
Set year = 10
Set check(year)? printf("%d is a Leap Year",year): printf("\n%d is not a Leap Year",year);
Stop示例
#include <stdio.h>
#include <stdbool.h>
//布尔检查年份是否为a年
bool check(int year){
//如果一年是400的倍数或4的倍数,则它是a年
if (year % 400 == 0 || year%4 == 0)
return true;
else
return false;
}
int main(){
int year = 2000;
check(year)? printf("%d is a Leap Year",year): printf("%d is not a Leap Year",year);
year = 101;
check(year)? printf("%d is a Leap Year",year): printf("\n%d is not a Leap Year",year);
return 0;
}输出结果
2000 is a Leap Year 101 is not a Leap Year
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短