week.c

来自「收集到的一些常用功能模块」· C语言 代码 · 共 46 行

C
46
字号
#include<iostream.h>
#include<string.h>
#include<iomanip.h>

typedef unsigned char int8u;
typedef unsigned int  int16u; 
typedef struct
{
	unsigned int Yea;
	unsigned char Mon;
	unsigned char Day;
}TDate;

unsigned char MonDayCount[12]={31,28,31,30,31,30,31,31,30,31,30,31};
unsigned char JudgeWeekDay(TDate curdate)
{
	unsigned int x,s,c;
	unsigned char i;
	x = curdate.Yea;
	c = 0;
	for(i=1;i<curdate.Mon;i++)
	{
		c += MonDayCount[i-1];  
	}
	c = c + curdate.Day;
	if((x%4==0)&&(x%100 != 0)||(x%400 == 0))
	{
		c++;
	}
	x = x-1;
	s = x + x/4 - x/100 + x/400 + c;
	i = s%7;
	return i;
}
void main(void)
{
	TDate CurrentDate;
	cout << "this is a test the weekday function:\n";
	cout << "Please input the year which you want to test:";
	cin >> CurrentDate.Yea;
	cout << "Month is :";
	cin >> CurrentDate.Mon;
	cout << "Date is :";
	cin >> CurrentDate.Day;
	cout >>"the date is : ">>JudgeWeekDay(CurrentDate);
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?