输入2001年至2100年之间任意年份,输出该年与2001年之间的闰年个数

我的这个输出的是闰年年份,请问要怎么修改才能输出闰年个数呢?

img


运行是这个样子

img

7、8行之间加一句 count++;

首先你的代码存在的问题就是count前面少了个int,先要初始化count才能正常存值;

int count=0;

其次,你的for循环中判断闰年的if之后应该让count+1(也就是count++),每有一个闰年count应该+1;

if ((i%4==0)&&(i%100/!=0))
    count++;

最后的输出应该放在for循环外面,完整代码如下:

#include <stdio.h>
int main()
{
    int i;
    int count=0;
    for (i=2001;i<=2100;i++)
    {
        if ((i%4==0)&&(i%100!=0))
        {
            count=count+1;
        }
    }
    printf("%d",count);
    return 0;
}

我感觉你写的没有\n,所以加载错误,建议更改到以下代码

#include <stdio.h>
int main(){
    int count;
    for (int i = 2001;i<2101;i++)
        if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
            printf(i)
            count++
        };
    };
    printf(count);
    return 0;
};