闰年个数(非循环)
#include <stdio.h> int main() { int n, i, count = 0, test; scanf("%d", &n); for (i = 1; i <= n; ++i)// 循环版 { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { ++count; } } // 非循环 test = n / 4 - n / 100 + n / 400;// 直接算闰年个数,不用循环 printf("test: %d\ncount: %d", test, count); return 0; }
========================================Talk is cheap, show me the code=======================================
CSDN博客地址:https://blog.csdn.net/qq_34115899