c语言 确定母亲节
发布网友
发布时间:2023-01-20 05:36
我来回答
共1个回答
热心网友
时间:2023-11-27 04:21
#include<stdio.h>
int year, month, day, week;
int century, year_2;
int m_year, m_month, m_day, m_week;
void main()
{
// scanf("%d",&y);
// scanf_s("%d-%d-%d",&year, &month, &day, 10);
scanf_s("%d", &year);
month = 5;
day = 1;
m_year = year;
m_month = month;
century = year / 100;
year_2 = year % 100;
week = (year_2 + (int)(year_2 / 4.0) + (int)(century / 4.0) - (2 * century) + (int)((26 * (month + 1)) / 10.0) + day - 1);
week = week % 7; //上面算出来的值有可能为负值,负值%7还为负值,所以加if判断
if(week <= 0)
week = week + 7;
printf("%d年%d月%d日是星期%d\n", year, month, day, week);
m_day = 15 - week;
printf("%d年母亲节是%d月%d日\n", m_year, m_month, m_day);
}
热心网友
时间:2023-11-27 04:21
#include<stdio.h>
int year, month, day, week;
int century, year_2;
int m_year, m_month, m_day, m_week;
void main()
{
// scanf("%d",&y);
// scanf_s("%d-%d-%d",&year, &month, &day, 10);
scanf_s("%d", &year);
month = 5;
day = 1;
m_year = year;
m_month = month;
century = year / 100;
year_2 = year % 100;
week = (year_2 + (int)(year_2 / 4.0) + (int)(century / 4.0) - (2 * century) + (int)((26 * (month + 1)) / 10.0) + day - 1);
week = week % 7; //上面算出来的值有可能为负值,负值%7还为负值,所以加if判断
if(week <= 0)
week = week + 7;
printf("%d年%d月%d日是星期%d\n", year, month, day, week);
m_day = 15 - week;
printf("%d年母亲节是%d月%d日\n", m_year, m_month, m_day);
}