栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++自定义函数判断某年某月某日是这一年中第几天

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++自定义函数判断某年某月某日是这一年中第几天

本文实例讲述了C++自定义函数判断某年某月某日是这一年中第几天的方法。分享给大家供大家参考,具体如下:


#include
using namespace std;
int main()
{
 void f(int year,int month,int day);
 int year,month,day;
 cout<<"请输入年月日:"<>year>>month>>day;
  if(f1(year,month,day))
  {
   if(leap(year))
   {
    for(i=0;i<=month-2;i++)
    {
     t=t+b[i];
    }
    s=t+day;
   }
   else
   {
    for(i=0;i<=month-2;i++)
    {
     t=t+a[i];
    }
    s=t+day;
   }
   cout<<"这是这一年的第"<0)
 {
  if(month>=1&&month<=12)
  {
   if(days(year,month,day))
   {
    return true;
   }
   else
    return false;
  }
  else
   return false;
 }
 else
  return false;
}
//判断输入的天 是否合法!
int days(int year,int month,int day)
{
 int leap(int year);
 if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
 {
  if(day>0&&day<=31)
  {
   return true;
  }
  else
   return false;
 }
 else if(month==2||month==4||month==6||month==9||month==11)
 {
  if(day>0&&day<=30)
  {
   return true;
  }
  else
   return false;
 }
 else
 {
  if(leap(year))
  {
   if(day>0&&day<=29)
   {
    return true;
   }
   else
    return false;
  }
  else
  {
   if(day>0&&day<=28)
   {
    return true;
   }
   else
    return false;
  }
 }
}

运行效果如下图所示:

PS:这里再为大家推荐一款C语言在线格式化工具,相信在以后的开发中可以用得上:

C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json

希望本文所述对大家C++程序设计有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/64373.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号