c语言判断某一年是否为闰年的各种实现程序代码

本文导语: c语言判断某一年是否为闰年的各种实现程序代码1、公历闰年计算原则(按一回归年365天5小时48分45.5秒)1)普通年能整除4且不能整除100的为闰年。(如2004年就是闰年,1900年不是闰年)2)世纪年能整除400的是闰年。(如2000年是闰年...

c语言判断某一年是否为闰年的各种实现程序代码

1、公历闰年计算原则(按一回归年365天5小时48分45.5秒)

1)普通年能整除4且不能整除100的为闰年。(如2004年就是闰年,1900年不是闰年)

2)世纪年能整除400的是闰年。(如2000年是闰年,1900年不是闰年)

3)对于数值很大的年份,这年如果能被3200整除,并且能被172800整除则是闰年。如172800年是闰年,86400年不是闰年(因为虽然能被3200整除,但不能被172800整除)(此按一回归年365天5h48‘45.5‘‘计算)。

2、公历闰年程序判断语句

if( ((0 == year%4)&&(0 != year%100)) ||(0 == year %400) )

{

//满足该条件的yeat就是闰年。

}

3、公历闰年程序代码(由www.169it.com搜集自互联网)

公历闰年实现代码一:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

#include <stdio.h>

void main()

{

 int year,leap;

 scanf("%d",&year);

 if(year%4==0)

 {

  if(year%100!=0)

   leap=1;

  else

  {

   if(year%400==0)

    leap=1;

   else

    leap=0;

  }

 }

 if(leap==1)

  printf("%d是闰年n",year);

 else

  printf("%d不是闰年n",year);}

公历闰年实现代码二:


1

2

3

4

5

6

7

8

9

10

#include <stdio.h>

void main()

{

 int year,leap;

 scanf("%d",&year);

 if(year%400==0||year%4==0&&year%100!=0)

  printf("%d是闰年n",year);

 else

  printf("%d不是闰年n",year);

}

公历闰年实现代码三:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

#include<stdio.h>

int main()

{

int year;

year=1900;

while(year<=2000)

{

if(year%400==0||year%4==0&&year%100!=0)

{

printf("%d是闰年n",year);

year++;

}

else year++;

}

return 0;

}

以上代码,仅供参考。

原文地址:https://www.cnblogs.com/w521w/p/9005928.html

时间: 2024-07-30 17:27:08

c语言判断某一年是否为闰年的各种实现程序代码的相关文章

C语言判断1000—2000年之间的闰年

闰年判断方法: 1.能被400整除的年份: 2.能被4整除但同时不能被100整除的年份. 满足上述两个条件之一的即为闰年. 以下展现了三种形式 第一种: #include<stdio.h> int main() { int year,leap,count=0;     for(year=1000;year<=2000;year++)     {if(year%4==0)      {if(year%100==0)      {      if(year%400==0)          

反汇编--C语言(判断与分支)

if  else条件判断 C语言实现: void Conditional(int c){ if (c>0 && c<10) { printf("c大于0,小于10"); } else if(c>10 && c<100) { printf("c大于10,小于100"); } else{ printf("其它"); } } void main(){ int num=5; Conditional(

C语言判断系统数据大/小端存储方式

小端存储:数据的低位部分,存储于存储器的低地址空间里. 大端存储:数据的低位部分,存储于存储器的高地址空间里. 首先,一般PC数据存储方式是小端存储. 基本实现思想是:将存储器中所存的数据按字节以地址顺序输出,与存入数据的高低位进行比较,即得出结论. 实现方法一: 1 #include <stdio.h> 2 int main(void) 3 { 4 short int x; 5 char *arr; 6 7 x = 0x1122; 8 arr = (char *)&x; 9 10 i

使用C语言判断栈的方向

这一问题主要是如何判读出先后入栈的变量的地址大小,比如有a, b两个变量一先一后被定义,如果a的地址大于b的地址,则说明是以低地址方向增长的,反之,往高地址方向增长. 在写C程序的时候不能简单直接的定义两个变量来比较它们的地址大小,因为这样很有可能编译器会做优化,最终导致结果不真实.为避免这种编译器优化的情况,可以采用将变量定义到函数中,然后递归调用该函数.例如下面的代码: #include <stdio.h> static int stack_direction = 0; static vo

c语言判断平年/闰年

要求: 用户输入年份之后,判断输入的是平年还是闰年 #include<stdio.h> #include<stdlib.h> #include<string.h> intmain(void) { //定义变量 int year = 0; int temp = 0; int temp1 = 0; //提示用户输入年份 printf("请输入年份:"); scanf("%d",&year); //首先判断当前的年份是否为整百或

【C语言】03-第一个C程序代码分析

前面我们已经创建了一个C程序,接下来分析一下里面的代码. 项目结构如下: 一.代码分析 打开项目中的main.c文件(C程序的源文件拓展名为.c),可以发现它是第一个C程序中的唯一一个源文件,代码如下: 1 #include <stdio.h> 2 3 int main(int argc, const char * argv[]) 4 { 5 6 // insert code here... 7 printf("Hello, World!\n"); 8 return 0;

判断某一年是否为闰年

1 package 判断某一年是否为闰年; 2 3 import java.util.Scanner; 4 5 public class If_LeapYear { 6 public static void main(String[] args) { 7 System.out.println("请输入年份"); 8 Scanner input=new Scanner(System.in); 9 boolean loop=true; 10 loop1: while(loop){ 11 t

C语言基础:将整数格式化成其它进制输出的代码

如下的资料是关于C语言基础:将整数格式化成其它进制输出的代码. #include <stdio.h> int main () { int value = 255; printf("The decimal value %d in octal is %on", value, value); printf("The decimal value %d in hexadecimal is %xn", value, value); printf("The

搞几款由“Python”语言编写的“有趣、恶搞、好玩”的程序代码!

为提高大家对"Python"编程语言的学习兴趣,今天给大家分享几款有趣的Python程序代码,感兴趣的小伙伴可以跟着学习借鉴哦!进群:839383 765可以获取Python学习资料哦! 分享一:"啥是佩奇?"让Python语言告诉你用Python代码创作一副佩奇: <pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Co