在C语言中编写一个程序,用于检查给定的年份是否为闰年

在c语言中编写一个程序,用于检查给定的年份是否为闰年

闰年有366天,而普通年有365天,任务是通过程序检查给定的年份是否为闰年。

判断的逻辑可以通过检查年份是否能被400或4整除来实现,但如果不能被这两个数整除,则为普通年。

示例

Input-: year=2000Output-: 2000 is a Leap YearInput-: year=101Output-: 101 is not a Leap year

登录后复制

算法

StartStep 1 -> declare function bool to check if year if a leap year or notbool check(int year)   IF year % 400 = 0 || year%4 = 0      return true   End   Else      return false   EndStep 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("

%d is not a Leap Year",year);Stop

登录后复制

Example

<!—

Live Demo

–>

#include #include //bool to check if year if a leap year or notbool check(int year){   // If a year is multiple of 400 or multiple of 4 then it is a leap year   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("

%d is not a Leap Year",year);   return 0;}

登录后复制

输出

2000 is a Leap Year101 is not a Leap Year

登录后复制

以上就是在C语言中编写一个程序,用于检查给定的年份是否为闰年的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2580826.html

(0)
上一篇 2025年3月6日 13:50:39
下一篇 2025年3月6日 13:50:44

AD推荐 黄金广告位招租... 更多推荐

相关推荐

发表回复

登录后才能评论