程序检查给定年份是否为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
热门推荐
1 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练