展开全部
下面是代码,switch 的自己想想看吧
01.#include"stdio.h"
02.int main()
03.{
04.
int a[13]={0};
05.
int nian,yue,ri,sum,i;
06.
char b,d;
07.
08.
while(scanf("%d %c %d %c %d",&nian,&b,&yue,&d,&ri)!=EOF)
09.
{a[1]=31;a[2]=28;a[3]=31;a[4]=30;a[5]=31;a[6]=30;a[7]=31;
10.
a[8]=31;a[9]=30;a[10]=31;a[11]=30;a[12]=31;
11.
sum=0;
12.
if((nian%4==0)&&(nian%400==0||nian%100!=0))a[2]=29;
13.
if(yue==1)
14.
sum+=ri;
15.
else
16.
{sum=a[1];
17.
for(i=2;i<yue;i++)
18.
sum+=a[i];
19.
sum+=ri;
20.
}
21.
printf("%d\n",sum);
22.
}return 0;
23.}
01.#include"stdio.h"
02.int main()
03.{
04.
int a[13]={0};
05.
int nian,yue,ri,sum,i;
06.
char b,d;
07.
08.
while(scanf("%d %c %d %c %d",&nian,&b,&yue,&d,&ri)!=EOF)
09.
{a[1]=31;a[2]=28;a[3]=31;a[4]=30;a[5]=31;a[6]=30;a[7]=31;
10.
a[8]=31;a[9]=30;a[10]=31;a[11]=30;a[12]=31;
11.
sum=0;
12.
if((nian%4==0)&&(nian%400==0||nian%100!=0))a[2]=29;
13.
if(yue==1)
14.
sum+=ri;
15.
else
16.
{sum=a[1];
17.
for(i=2;i<yue;i++)
18.
sum+=a[i];
19.
sum+=ri;
20.
}
21.
printf("%d\n",sum);
22.
}return 0;
23.}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
using namespace std;
int main()
{
int year,month,day; //年 月 日
int days; //计算总天数
cout<<"please input the year.month.day:"<<endl;
cin>>year>>month>>day;
switch(month)
{
case 0:break;
case 1:days=day;break;
case 2:days=day+31;break;
case 3:days=day+59;break;
case 4:days=day+90;break;
case 5:days=day+120;break;
case 6:days=day+151;break;
case 7:days=day+181;break;
case 8:days=day+212;break;
case 9:days=day+243;break;
case 10:days=day+273;break;
case 11:days=day+304;break;
case 12:days=day+335;break;
default:cout<<"输入错误.";break;
}
if((year%4==0)&&(year%100!=0)||(year%400==0))
if(month>2)
days+=1;
cout<<year<<"年"<<month<<"月是这一年的第"<<days<<"天"<<endl;
return 0;
}
using namespace std;
int main()
{
int year,month,day; //年 月 日
int days; //计算总天数
cout<<"please input the year.month.day:"<<endl;
cin>>year>>month>>day;
switch(month)
{
case 0:break;
case 1:days=day;break;
case 2:days=day+31;break;
case 3:days=day+59;break;
case 4:days=day+90;break;
case 5:days=day+120;break;
case 6:days=day+151;break;
case 7:days=day+181;break;
case 8:days=day+212;break;
case 9:days=day+243;break;
case 10:days=day+273;break;
case 11:days=day+304;break;
case 12:days=day+335;break;
default:cout<<"输入错误.";break;
}
if((year%4==0)&&(year%100!=0)||(year%400==0))
if(month>2)
days+=1;
cout<<year<<"年"<<month<<"月是这一年的第"<<days<<"天"<<endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
void main()
{
int year,month,num=0;
printf("input year and month:\n");
scanf("%d%d",&year,&month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:num=31;break;
case 4:
case 6:
case 9:
case 11:num=30;break;
case 2:{
if((year%4==0&&year%100!=0)||(year%400==0))
num=29;
else num=28;
break;}
}
printf("num=%d\n",num);
}
差不多吧
void main()
{
int year,month,num=0;
printf("input year and month:\n");
scanf("%d%d",&year,&month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:num=31;break;
case 4:
case 6:
case 9:
case 11:num=30;break;
case 2:{
if((year%4==0&&year%100!=0)||(year%400==0))
num=29;
else num=28;
break;}
}
printf("num=%d\n",num);
}
差不多吧
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "stdio.h"
#include "string.h"
int order(int Year, int Month)
{
int LeapYear;
LeapYear = Year%(Year%100?4:400)?0:1;
switch(Month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 2:
if(LeapYear)
return 29;
else
return 28;
case 4:
case 6:
case 9:
case 11:
return 30;
default:
return 0;
}
}
void main()
{
int Day,Year,Month;
do
{
printf("输入:\n年 = ");
scanf("%d",&Year);
printf("月 = ");
scanf("%d",&Month);
Day = order(Year,Month);
printf("当月天数 = %d\n",Day);
printf("重新输入日期请输入 y\n\n");
}
while(getch() == 'y');
}
#include "string.h"
int order(int Year, int Month)
{
int LeapYear;
LeapYear = Year%(Year%100?4:400)?0:1;
switch(Month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 2:
if(LeapYear)
return 29;
else
return 28;
case 4:
case 6:
case 9:
case 11:
return 30;
default:
return 0;
}
}
void main()
{
int Day,Year,Month;
do
{
printf("输入:\n年 = ");
scanf("%d",&Year);
printf("月 = ");
scanf("%d",&Month);
Day = order(Year,Month);
printf("当月天数 = %d\n",Day);
printf("重新输入日期请输入 y\n\n");
}
while(getch() == 'y');
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询