#includestdio.h
成都创新互联从2013年成立,先为雨花台等服务建站,雨花台等地企业,进行企业商务咨询服务。为雨花台企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
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");
}
}
#include stdio.h
#include time.h
int main() {
int year, month, day;
printf("Enter a date (yyyy-mm-dd): ");
scanf("%d-%d-%d", year, month, day);
struct tm tm = {0};
tm.tm_year = year - 1900;
tm.tm_mon = month - 1;
tm.tm_mday = day;
tm.tm_isdst = -1;
time_t t = mktime(tm);
char* weekday[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
printf("%s\n", weekday[localtime(t)-tm_wday]);
return 0;
}
在这段代码中,使用了 time 库中的 mktime 函数和 localtime 函数来将日期转换为时间戳,并使用 tm_wday 字段来计算日期是星期几。
#include stdio.h
void main(){
int date;
char week[7][3]={"六","天","一","二","三","四","五"};
scanf("%d",date);
if(date=1date=30)
{
date-=11;
while(date0) date+=7;
printf("星期%s",week[date%7]);
}
else printf("输入日期有误!");
}
//运行示例: