第十一周项目 5 当年第几天
来源:互联网 发布:逆战淘宝代练1元一把 编辑:程序博客网 时间:2024/05/16 09:17
/* *Copyright (c) 2014,烟台大学计算机学院 *All rights reserved. *文件名称 :soul.cpp *作 者 :韩娟 *完成日期 :2014年11月6日 *版 本 号 :v1.0 * *问题描述 :定义一个函数,其参数为年,月,日的值,返回这一天为该年的第几天 *输入描述 :输入年月日 *程序输出 :输出这天是该年的第几天 */#include <iostream>using namespace std;int days(int y, int m, int d);int main(){ int year, month, day; cout<<"输入年 月 日"<<endl; cin>>year>>month>>day; cout<<"这是该年的第"<<days(year, month, day)<<"天"<<endl; return 0;}int days(int y, int m, int d){ int sum=d; for(int i=1; i<=m; ++i) { switch(i) { case 2: sum=sum+((y%4==0&&y%100!=0||y%400==0)?29:28); break; case 4: case 6: case 9: case 11: sum=sum+30; break; default: sum=sum+31; break; } } return sum;}
知识点总结 :
利用一个语句来进行天数的累加,从而得到目的。
学习心得 :
这个项目要用一个switch语句来进行,用switch的时候要有default来否定,进行这个程序。
0 0
- 第十一周项目5-当年第几天
- 第十一周项目 5 当年第几天
- 第十一周项目5--当年第几天
- 第十一周项目5--当年第几天
- 第十一周项目5当年第几天
- 第十一周项目5-当年第几天
- 第十一周项目5当年第几天
- 第十一周 项目5:当年第几天
- 第十一周项目5-当年第几天
- 第十一周项目5--当年第几天
- 第十一周项目五 当年第几天
- 第十一周项目五: 当年第几天
- 第十一周项目-当年第几天
- 第十一周项目五 当年第几天
- 第十一周 项目五: 当年第几天
- 第十一周项目五:当年第几天
- 第十一周 项目五 当年第几天
- 第十一周项目五:当年第几天
- easyui-tabs根据数据库的数据动态生产tab
- Android Launcher分析和修改1——Launcher默认界面配置(default_workspace)
- Qt for Android 配置详细 (linux下的)
- jqMobi插件(2)--JSON格式的ActionSheet
- 读“企鹅物联,靠谱吗?”有感
- 第十一周项目 5 当年第几天
- history.go(-1)在不同浏览器中的解析
- C#调用 JS 方法
- MSVCRTD.lib(crtexe.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStart
- Oracle 之——子查询 DDL DML 集合 及其他数据对象
- mysql导入数据file not found解决方案
- 1000内素数 1000内回文数
- 使用 VS 2012 编译 GTest 遇到的编译错误
- Div里面载入另一个页面的实现(取代框架)(AJax)