这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 高校专区 » 岭南EE码农港 » 查询一年中哪个月有31天

共1条 1/1 1 跳转至

查询一年中哪个月有31天

菜鸟
2014-11-26 21:59:45     打赏
#include"stdio.h" 
void main() 
{ 
int leap(int y); 
int year,month,day; 
int sum=0,i,m[12]={31,0,31,30,31,30,31,31,30,31,30,31}; 
printf("Input a year,month,day:"); 
scanf ("%d,%d,%d",&year,&month,&day); 
if (leap(year)) 
{m[1]=29;} 
else 
{m[1]=28;} 
for (i=0;i<=(month-2);i++) 
{sum+=m[i];} 
sum+=day; 
printf ("Total=%d\n",sum); 
} 
int leap(int y) 
{ 
int leapyear=0; 
if (y%4!=0) 
leapyear=0; 
else if (y%100!=0) 
leapyear=1; 
else if (y%400!=0) 
leapyear=0; 
else 
leapyear=1; 
return(leapyear); 
} 

 

#include"stdio.h"
void main()
{
int leap(int y);
int year,month,day;
int sum=0,i,m[12]={31,0,31,30,31,30,31,31,30,31,30,31};
printf("Input a year,month,day:");
scanf ("%d,%d,%d",&year,&month,&day);
if (leap(year))
{m[1]=29;}
else
{m[1]=28;}
for (i=0;i<=(month-2);i++)
{sum+=m[i];}
sum+=day;
printf ("Total=%d\n",sum);
}
int leap(int y)
{
int leapyear=0;
if (y%4!=0)
leapyear=0;
else if (y%100!=0)
leapyear=1;
else if (y%400!=0)
leapyear=0;
else
leapyear=1;
return(leapyear);
}

 




关键词: 31天 某个月    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]