oj-11-A-判断闰年

来源:互联网 发布:java 打包maven工程 编辑:程序博客网 时间:2024/06/06 19:01
#include <stdio.h>#include <stdlib.h>#include <stdio.h>int leap_year(int n);   /*声明判断闰年函数*/int main(){    int i;    int cnt;    /*计数,用于每行满8个换行*/    int m,n;    scanf("%d %d",&m,&n);   /*输入年份*/    cnt=0;  /*初始化*/    for(i=m;i<=n;i++)   /*遍历m到n的每一年*/    {        if(leap_year(i))    /*判断i年是不是闰年*/        {            printf("%d",i); /*输出闰年*/            cnt++;  /*计数+1*/            if(cnt==8) /*够8个换行,cnt清0*/            {                printf("\n");                cnt=0;            }            else            {                printf(" ");            }        }    }    return 0;}int leap_year(int n){     int i=0;    if(n%4==0)    {        if(n%100!=0)            i=1;    }    if(n%400==0)    i=1;    return i;}

知识点总结:这个是一个新知识,用到了自定义函数,以后应当建立这种思维。

学习心得:要学会使用函数。

0 0
原创粉丝点击