C语言输入年份和天数输出对应的年月日
3个回答
展开全部
C语言输入年份和天数输出对应的年月日的源代码如下:
#include <iostream>
int day(int &year, int &month);
int main()
{
int year{};
int month{};
std::cout << "请输入年和月(空格隔开):";
std::cin >> year >> month;
std::cout << "该月天数:" << day(year, month) << '\n';
return 0;
}
扩展资料
1、C++ 标准库没有提供所谓的日期类型。C++ 继承了 C 语言用于日期和时间操作的结构和函数。为了使用日期和时间相关的函数和结构,需要在 C++ 程序中引用 <ctime> 头文件。
2、有四个与时间相关的类型:clock_t、time_t、size_t 和 tm。类型 clock_t、size_t 和 time_t 能够把系统时间和日期表示为某种整数。
展开全部
#include "stdio.h"
bool ifLeapYear(int year)//判断是不是云年
{
if((year%400==0)||((year%4==0)&&(year%100!=0)))
return true;
else
return false;
}
void main()
{
int year,date,i;
int month1[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int month2[12]={31,28,31,30,31,30,31,31,30,31,30,31};
bool flag;
printf("请输入年份和天数\n");
scanf("%d%d",&year,&date);
if(date>366)
{
printf("输入错误!\n");
return;
}
flag=ifLeapYear(year);
if(flag)
for(i=0;i<12;i++)
{
if(date<=month1[i]) break;
date=date-month1[i];
}
else
for(i=0;i<12;i++)
{
if(date<=month2[i]) break;
date=date-month2[i];
}
printf("是%d月%d号",i+1,date);
}
bool ifLeapYear(int year)//判断是不是云年
{
if((year%400==0)||((year%4==0)&&(year%100!=0)))
return true;
else
return false;
}
void main()
{
int year,date,i;
int month1[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int month2[12]={31,28,31,30,31,30,31,31,30,31,30,31};
bool flag;
printf("请输入年份和天数\n");
scanf("%d%d",&year,&date);
if(date>366)
{
printf("输入错误!\n");
return;
}
flag=ifLeapYear(year);
if(flag)
for(i=0;i<12;i++)
{
if(date<=month1[i]) break;
date=date-month1[i];
}
else
for(i=0;i<12;i++)
{
if(date<=month2[i]) break;
date=date-month2[i];
}
printf("是%d月%d号",i+1,date);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "stdio.h"
main()
{
int year,month,day,i;
scanf("%d",&year);
scanf("%d",&i);
if((year%4==0&&year%100!=0)||year%400==0)
{
if(i>0&&i<=366)
{
if(i<=31){month=1;printf("%d年%d月%d日",year,month,i);}
else if(i<=60){month=2;printf("%d年%d月%d日",year,month,i-31);}
else if(i<=91){month=3;printf("%d年%d月%d日",year,month,i-60);}
else if(i<=121){month=4;printf("%d年%d月%d日",year,month,i-91);}
else if(i<=152){month=5;printf("%d年%d月%d日",year,month,i-121);}
else if(i<=182){month=6;printf("%d年%d月%d日",year,month,i-152);}
else if(i<=213){month=7;printf("%d年%d月%d日",year,month,i-182);}
else if(i<=244){month=8;printf("%d年%d月%d日",year,month,i-213);}
else if(i<=274){month=9;printf("%d年%d月%d日",year,month,i-244);}
else if(i<=305){month=10;printf("%d年%d月%d日",year,month,i-274);}
else if(i<=335){month=11;printf("%d年%d月%d日",year,month,i-305);}
else {month=12;printf("%d年%d月%d日",year,month,i-335);}
}
else
printf("输入的日期超出范围");
}
else
{
if(i>0&&i<=365)
{
if(i<=31){month=1;printf("%d年%d月%d日",year,month,i);}
else if(i<=59){month=2;printf("%d年%d月%d日",year,month,i-31);}
else if(i<=90){month=3;printf("%d年%d月%d日",year,month,i-59);}
else if(i<=120){month=4;printf("%d年%d月%d日",year,month,i-90);}
else if(i<=151){month=5;printf("%d年%d月%d日",year,month,i-120);}
else if(i<=181){month=6;printf("%d年%d月%d日",year,month,i-151);}
else if(i<=212){month=7;printf("%d年%d月%d日",year,month,i-181);}
else if(i<=243){month=8;printf("%d年%d月%d日",year,month,i-212);}
else if(i<=273){month=9;printf("%d年%d月%d日",year,month,i-243);}
else if(i<=304){month=10;printf("%d年%d月%d日",year,month,i-273);}
else if(i<=334){month=11;printf("%d年%d月%d日",year,month,i-304);}
else {month=12;printf("%d年%d月%d日",year,month,i-334);}
}
else
printf("输入的日期超出范围");
}
}
希望对你有帮助
main()
{
int year,month,day,i;
scanf("%d",&year);
scanf("%d",&i);
if((year%4==0&&year%100!=0)||year%400==0)
{
if(i>0&&i<=366)
{
if(i<=31){month=1;printf("%d年%d月%d日",year,month,i);}
else if(i<=60){month=2;printf("%d年%d月%d日",year,month,i-31);}
else if(i<=91){month=3;printf("%d年%d月%d日",year,month,i-60);}
else if(i<=121){month=4;printf("%d年%d月%d日",year,month,i-91);}
else if(i<=152){month=5;printf("%d年%d月%d日",year,month,i-121);}
else if(i<=182){month=6;printf("%d年%d月%d日",year,month,i-152);}
else if(i<=213){month=7;printf("%d年%d月%d日",year,month,i-182);}
else if(i<=244){month=8;printf("%d年%d月%d日",year,month,i-213);}
else if(i<=274){month=9;printf("%d年%d月%d日",year,month,i-244);}
else if(i<=305){month=10;printf("%d年%d月%d日",year,month,i-274);}
else if(i<=335){month=11;printf("%d年%d月%d日",year,month,i-305);}
else {month=12;printf("%d年%d月%d日",year,month,i-335);}
}
else
printf("输入的日期超出范围");
}
else
{
if(i>0&&i<=365)
{
if(i<=31){month=1;printf("%d年%d月%d日",year,month,i);}
else if(i<=59){month=2;printf("%d年%d月%d日",year,month,i-31);}
else if(i<=90){month=3;printf("%d年%d月%d日",year,month,i-59);}
else if(i<=120){month=4;printf("%d年%d月%d日",year,month,i-90);}
else if(i<=151){month=5;printf("%d年%d月%d日",year,month,i-120);}
else if(i<=181){month=6;printf("%d年%d月%d日",year,month,i-151);}
else if(i<=212){month=7;printf("%d年%d月%d日",year,month,i-181);}
else if(i<=243){month=8;printf("%d年%d月%d日",year,month,i-212);}
else if(i<=273){month=9;printf("%d年%d月%d日",year,month,i-243);}
else if(i<=304){month=10;printf("%d年%d月%d日",year,month,i-273);}
else if(i<=334){month=11;printf("%d年%d月%d日",year,month,i-304);}
else {month=12;printf("%d年%d月%d日",year,month,i-334);}
}
else
printf("输入的日期超出范围");
}
}
希望对你有帮助
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询