#includestdio.h
創(chuàng)新互聯公司專注于宜君網站建設服務及定制,我們擁有豐富的企業(yè)做網站經驗。 熱誠為您提供宜君營銷型網站建設,宜君網站制作、宜君網頁設計、宜君網站官網定制、成都小程序開發(fā)服務,打造宜君網絡公司原創(chuàng)品牌,更為您提供宜君網站排名全網營銷落地服務。
int isRn(int num){
if((num%4==0num%400!=0)||num%400==0){
return 1;
}else{
return 0;
}
int monthDay(int year,int month){
if(month==1||month==3||month==5
||month==7||month==8||month==10
||month==12){
return 31;
}else if(month==4||month==6||month==9
||month==11)
{
return 30;
}else if(month==2){
if(isRn(int num)==1){
return 29;
}else{
return 28;
}
}
}
void main(){
int sum=0,year,month,day,i,temp,j;
printf("請輸入年份:");
scanf("%d",year);
while(year1900){
printf("年份必須從1900年開始!\n\n");
printf("請輸入年份:");
scanf("%d",year);
}
printf("請輸入月份:");
scanf("%d",month);
while(month1||month12){
printf("月份必須是1到12之間!\n\n");
printf("請輸入月份:");
scanf("%d",month);
}
printf("請輸入日:");
scanf("%d",day);
while(daymonthDay(year,month)||day1){
printf("日必須從1開始,并且不能大于該月的天數!\n\n");
printf("請輸入日:");
scanf("%d",day);
}
temp=month;
temp-=1;
for(i=1900;i=year;i++){
for(j=1;j=12;j++){
if(i==yearj==temp){
break;
}
sum+= monthDay(year,j);
}
}
sum+=day;
printf("%d年%d月%d日,是星期",year,month,day)
if(sum%7==0){
printf("日。\n");
}else if(sum%7==1){
printf("一。\n");
}else if(sum%7==2){
printf("二。\n");
}else if(sum%7==3){
printf("三。\n");
}else if(sum%7==4){
printf("四。\n");
}else if(sum%7==5){
printf("五。\n");
}else if(sum%7==2){
printf("六。\n");
}
}
注意:本源碼中,函數GetWeekDay的返回值僅僅表示輸入參數是否“正確/有效”(例如前三個參數使用2001,2,29就是無效參數),能否得到預期的星期值;真正的星期值則是通過輸出變量返回給主調函數的。
#include
time.h
#include
stdio.h
int
GetWeekDay(int
nYear,int
nMon,int
nDay,
int
*npWeekDay);
int
main()
{
int
nMyWeekDay;
int
nResult;
nResult
=
GetWeekDay(2007,1,10,nMyWeekDay);
return
0;
}
//輸入日期,返回星期的C語言函數
int
GetWeekDay(int
nYear,int
nMon,int
nDay,
int
*npWeekDay)
{
int
nRetVal
=
0;
time_t
tMyDateTime;
struct
tm
tmMyDate,*tmpMyDate;
if((nYear1900||nYear=3000)
||
(nMon1
||
nMon12)
||
(nDay1||nDay31)
)
{
nRetVal
=
1;
*npWeekDay
=
-1;
return
nRetVal;
}
//memset(tmMyDate,0,sizeof(struct
tm));
tmMyDate.tm_year
=
nYear-1900;
tmMyDate.tm_mon
=
nMon-1;
tmMyDate.tm_mday
=
nDay;
tmMyDate.tm_hour
=16;
tmMyDate.tm_min
=30;
tmMyDate.tm_sec
=30;
tMyDateTime
=
mktime(tmMyDate);
if(tMyDateTime0)
{
nRetVal
=
1;
*npWeekDay
=
-1;
return
nRetVal;
}
tmpMyDate
=
localtime(tMyDateTime);
*npWeekDay
=
tmpMyDate-tm_wday;
return
nRetVal;
}
y年m月d日,是第幾天days?。坑嬎惴椒ǎ篸ays=mon[1]+mon[2]+.+mon[m-1]+d;mon[i]是第i個月的天數;同時要注意,mon[2]閏年29,否則28;給出代碼吧,雖然這樣對你其實么有什么好處、#includeintmain(){intmon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};inty,m,d,days;intleap,i;scanf("%d%d%d",y,m,d);for(i=1,days=0;i2)days++;printf("days=%d\n",days);}自己讀,自己寫,經常百度,不好~~~剛才有個單詞打錯了,sorry、、~~