1:代码如下:

// 3.25.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <iostream>
using namespace std; int main(int argc, _TCHAR* argv[])
{
//若直接使用for循环遍历1773-2012年,则需要执行240次判断。 int year; //1773开始的第一个闰年
int yearStart = ;//代表从何年开始
int yearTo = ;//代表从何年结束 //其实可以将以下for循环条件设定为i<4,不过有些年份在世纪末,设定为i<8则是考虑到了这一点。
for(int i = ;i<;i++ )
{
if( (yearStart+i)%== && (yearStart+i)%!= || (yearStart+i)%==)
{
year = yearStart+i; //此时year为1773开始的第一个闰年
break;
}
}
int count = ; //闰年个数 for(int yearIter =year;yearIter<yearTo;count++)
{ if(yearIter% == &&yearIter% != )
{
yearIter+=;//每隔4年判断一次
count--;
continue;
} cout<<yearIter<<" ";
if(count% == )
{
cout<<endl; //每10个年份换行
}
yearIter+=;
}
cout<<endl;
//整个程序执行了共62次循环
return ;
}

运行结果:

C++入门经典-例3.25-使用循环输出闰年的更多相关文章

  1. C++入门经典-例4.5-利用循环求n的阶乘

    1:代码如下: // 4.5.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using ...

  2. C++入门经典-例3.23-使用嵌套循环输出乘法口诀表

    1:代码如下: // 3.23.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iomanip> #incl ...

  3. 【AngularJS入门】用ng-repeat指令实现循环输出

    循环输出列表很多项目在web服务端做,前端做好模版后后端写jsp代码,双方需要紧密合作,分清责任.有些项目由后端提供restful方法,前端用ajax调用自己循环,这种一般是大把的jquery拼字符串 ...

  4. C++入门经典-例3.18-使用for循环计算从1到10的累加

    1:代码如下: // 3.18.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...

  5. C++入门经典-例3.21-goto语句实现循环

    1:代码如下: // 3.21.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...

  6. C++入门经典-例3.17-使用while循环进行计算

    1:代码如下: // 3.17.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...

  7. C++入门经典-例3.16-使用do-while循环进行计算

    1:代码如下: // 3.16.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...

  8. C++入门经典-例3.15-使用do-while循环计算1到10的累加

    1:代码如下: // 3.15.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...

  9. C++入门经典-例3.14-使用while循环计算从1到10的累加

    1:代码如下: // 3.14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...

随机推荐

  1. Android新版xUtils3工具类相关debug

    首先出现问题是 build.gradle中的csayısıom.lidroid.xutils:xutils:2.6.13报错了,所以想到是版本的问题,github上搜了xutils发现有新版xutil ...

  2. IntelliJ IDEA setup JDK无效

    参考 问题现象:功能全部爆红,总是提示“setup JDK”,设置JDK后无效.但程序能够正常编译和运行. 解决方法:  File -> Invalidate Caches/Restart -& ...

  3. JS基础_数据类型-Null类型和Undefined类型

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. LOJ题解#136. 最小瓶颈路 DFS+Kruskal

    题目链接: https://loj.ac/problem/136 思路: 在我的这篇博客中已经讲到什么是最短瓶颈路,同时给出了一个用Kruskal求最短瓶颈路的一个简洁易懂的方法,然而这道题目可以看作 ...

  5. Vue报错:Property or method "XXX" is not defined on the instance but referenced during render. Make sure that this property is reactive...

    在Vue中定义方法或者属性时,因为粗心疏忽可以能会报该错误 [Vue warn]: Property or method "search" is not defined on th ...

  6. 微信小程序swiper使用网络图片不显示问题

    @ wxml代码: <view class="container"> <swiper indicator-dots="true}" autop ...

  7. Python内置函数清单

    作者:Vamei 出处:http://www.cnblogs.com/vamei Python内置(built-in)函数随着python解释器的运行而创建.在Python的程序中,你可以随时调用这些 ...

  8. 目录:Matrix Differential Calculus with Applications in Statistics and Econometrics,3rd_[Magnus2019]

    目录:Matrix Differential Calculus with Applications in Statistics and Econometrics,3rd_[Magnus2019] Ti ...

  9. 第十篇.1、python并发编程之多进程理论部分

    一 什么是进程 进程:正在进行的一个过程或者说一个任务.而负责执行任务则是cpu. 举例(单核+多道,实现多个进程的并发执行): egon在一个时间段内有很多任务要做:python备课的任务,写书的任 ...

  10. 从subversion开始(svn安装配置全过程(+全套安装文件与配置文件))…..

    从subversion开始(svn安装配置全过程(+全套安装文件与配置文件))-.. 博客分类: 工具使用 SVNsubversion配置管理Apache应用服务器  </div> 花了一 ...