两个吃奶一个添下面视频_人妻第一页香蕉网_欧美xxxx少妇_妺妺窝人体色www婷婷

  • 歡迎訪問C語言網(wǎng)www.sztianhecheng.cn 比賽欄每月有獎(jiǎng)月賽!舉辦比賽聯(lián)系QQ:2045302297
  • 問題反饋、粉絲交流 QQ群327452739 藍(lán)橋杯訓(xùn)練群:113766799 申請(qǐng)群時(shí)請(qǐng)備注排名里的昵稱
  • C語言研究中心 為您提供有圖、有料、解渴的C語言專題! 歡迎討論!

C語言小程序?qū)崿F(xiàn)萬年歷

項(xiàng)目源碼 CTO 21676次瀏覽 3個(gè)評(píng)論

分享一個(gè)簡(jiǎn)單的小程序,看看如何打印萬年歷吧~

程序打開時(shí)時(shí)這樣的,輸入一個(gè)年份:

C語言小程序?qū)崿F(xiàn)萬年歷

比如輸入2016再回車,效果如下:

C語言小程序?qū)崿F(xiàn)萬年歷

下面我們來看看實(shí)現(xiàn)這個(gè)程序的代碼吧:

#include<stdio.h>
#include<windows.h>

#define Mon 1
#define Tues 2
#define Wed 3
#define Thur 4
#define Fri 5
#define Sat 6
#define Sun 0

#define January_days 31
#define February_days 28
#define March_days 31
#define April_days 30
#define May_days 31
#define June_days 30
#define July_days 31
#define August_days 31
#define September_days 30
#define October_days 31
#define November_days 30
#define December_days 31

#define first1month January_days
#define first2month January_days+February_days
#define first3month January_days+February_days+March_days
#define first4month January_days+February_days+March_days+April_days
#define first5month January_days+February_days+March_days+April_days+May_days
#define first6month January_days+February_days+March_days+April_days+May_days+June_days
#define first7month January_days+February_days+March_days+April_days+May_days+June_days \
+July_days
#define first8month January_days+February_days+March_days+April_days+May_days+June_days \
+July_days+August_days
#define first9month January_days+February_days+March_days+April_days+May_days+June_days \
+July_days+August_days+September_days
#define first10month January_days+February_days+March_days+April_days+May_days+June_days \
+July_days+August_days+September_days+October_days
#define first11month January_days+February_days+March_days+April_days+May_days+June_days \
+July_days+August_days+September_days+October_days+November_days

int known_weekday = Tues;
int known_year = 1901;
int konwn_month = 1;
int known_day = 1;

int day_count(int month)
{
	switch(month)
	{
	case 1: return 0;break;
	case 2: return first1month;break;
	case 3: return first2month;break;
	case 4: return first3month;break;
	case 5: return first4month;break;
	case 6: return first5month;break;
	case 7: return first6month;break;
	case 8: return first7month;break;
	case 9: return first8month;break;
	case 10: return first9month;break;
	case 11: return first10month;break;
	case 12: return first11month;break;
	}
}


/*char * month_name(int month)
{
switch(month)
{
case 1:
return "January";
break;
case 2:
return "February";
break;
case 3:
return "March";
break;
case 4:
return "April";
break;
case 5:
return "May";
break;
case 6:
return "June";
break;
case 7:
return "July";
break;
case 8:
return "August";
break;
case 9:
return "September";
break;
case 10:
return "October";
break;
case 11:
return "November";
break;
case 12:
return "December";
break;
default:
break;
}
}*/

char * month_name(int month)
{
	switch(month)
	{
	case 1:
		return "一月";
		break;
	case 2:
		return "二月";
		break;
	case 3:
		return "三月";
		break;
	case 4:
		return "四月";
		break;
	case 5:
		return "五月";
		break;
	case 6:
		return "六月";
		break;
	case 7:
		return "七月";
		break;
	case 8:
		return "八月";
		break;
	case 9:
		return "九月";
		break;
	case 10:
		return "十月";
		break;
	case 11:
		return "十一月";
		break;
	case 12:
		return "十二月";
		break;
	default:
		break;
	}
}

/*按格式打印某年某月名稱*/
void first_line_print(int month, int year)
{
	//printf("%20s %d \n",month_name(month),year);
	printf("%8d年 %s \n",year, month_name(month));
}

/*按格式打印星期名稱*/
void week_print()
{
	//printf("%-6s%-6s%-6s%-6s%-6s%-6s%-6s\n","Sun.", "Mon.", "Tues.", "Wed.", "Thur.", "Fri.", "Sat.");
	printf("%-3s%-3s%-3s%-3s%-3s%-3s%-3s\n","日", "一", "二", "三", "四", "五", "六");
}

/*計(jì)算該年該月份與已知日子之間的距離天數(shù)*/
int date_distance_count(int month, int year)
{
	int leap_year_count = 0;
	int i;
	int distance;
	
	if (year > known_year)
	{
		for (i=known_year; i<year; i++)
		{
			if(((i%4 == 0) && (i%100 != 0) ) || (i%400 == 0))
			{
				leap_year_count++;
			}
		}
		
		if (month > 2)
		{
			if(((year%4 == 0) && (year%100 != 0) ) || (year%400 == 0))
			{
				leap_year_count++;
			}
		}
	}
	else
		if (year == known_year)
		{
			if (month > 2)
			{
				leap_year_count = 1;
			}
		}
		
		
		distance = (year - known_year)*365 + leap_year_count + day_count(month);
		
		return distance;
}

/*確定該月份第一天是星期幾*/
int makesure_firstday_weekday(int month, int year)
{
	int date_distance = 0;
	int weekday;
	
	date_distance = date_distance_count(month, year);
	weekday = (known_weekday + date_distance)%7;
	
	return weekday;
}

/*依次打印出該月份的日子*/
void print_in_turn(int month, int firstday, int year)
{
	int i = 1;
	int weekday;
	
	switch(firstday)
	{
	case Sun:
		break;
	case Mon:
		printf("%-3s","");
		break;
	case Tues:
		printf("%-6s","");
		break;
	case Wed:
		printf("%-9s","");
		break;
	case Thur:
		printf("%-12s","");
		break;
	case Fri:
		printf("%-15s","");
		break;
	case Sat:
		printf("%-18s","");
		break;
	}
	
	switch(month)
	{
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		{
			for(i=0; i<31; i++)
			{
				weekday = (firstday + i)%7;
				printf("%-3d",i+1);
				
				if(weekday == Sat)
				{
					printf("\n");
				}
			}
			break;
		}
	case 2:
		{
			if(((year%4 == 0) && (year%100 != 0) ) || (year%400 == 0)) /*閏年*/
			{
				for(i=0; i<29; i++)
				{
					weekday = (firstday + i)%7;
					printf("%-3d",i+1);
					
					if(weekday == Sat)
					{
						printf("\n");
					}
				}
				break;
			}
			else /*平年*/
			{
				for(i=0; i<28; i++)
				{
					weekday = (firstday + i)%7;
					printf("%-3d",i+1);
					
					if(weekday == Sat)
					{
						printf("\n");
					}
				}
				break;
			}
			
		}
	case 4:
	case 6:
	case 9:
	case 11:
		{
			for(i=0; i<30; i++)
			{
				weekday = (firstday + i)%7;/*計(jì)算該天是星期幾*/
				printf("%-3d",i+1);
				
				if(weekday == Sat)
				{
					printf("\n");/*如果是星期六,則換行*/
				}
			}
			break;
		}
	}
}

void date_print(int month, int year)
{
	int firstday;
	
	firstday = makesure_firstday_weekday(month, year);
	print_in_turn(month, firstday, year);
	printf("\n");
}

void main_month(int month, int year)
{
	first_line_print(month, year);
	week_print();
	date_print(month, year);
	printf("\n\n");
}

void main_calendar(int year)
{
	int i;
	for(i=1; i<=12; i++)
	{
		main_month(i, year);
	}
}

int main()
{
	int year;
	
	system("title c語言研究中心 www.sztianhecheng.cn");
	printf("請(qǐng)輸入年份:year = ");
	scanf("%d",&year);
	printf("\n");
	
	while(year < 1902)
	{
		printf("請(qǐng)輸入大于1901的年份\n");
		
		printf("請(qǐng)輸入年份:year = ");
		scanf("%d",&year);
		printf("\n");
	}
	
	main_calendar(year);
	
	scanf(" ");
	return 0;
}

C語言研究中心(www.sztianhecheng.cn)

C語言網(wǎng)提供「C語言、C++、算法競(jìng)賽」在線課程,全部由資深研發(fā)工程師或ACM金牌大佬親授課,更科學(xué)、全面的課程體系,以在線視頻+在線評(píng)測(cè)的學(xué)習(xí)模式學(xué)習(xí),學(xué)練同步,拒絕理論派,真正學(xué)會(huì)編程!還有獎(jiǎng)學(xué)金等增值福利等你!

C語言網(wǎng), 版權(quán)所有丨如未注明 , 均為原創(chuàng)丨本網(wǎng)站采用BY-NC-SA協(xié)議進(jìn)行授權(quán) , 轉(zhuǎn)載請(qǐng)注明C語言小程序?qū)崿F(xiàn)萬年歷!
喜歡 (55)
[jinyangH@aliyun.com]
分享 (0)
發(fā)表我的評(píng)論
取消評(píng)論
表情

Hi,您需要填寫昵稱和郵箱!

  • 昵稱 (必填)
  • 郵箱 (必填)
(3)個(gè)小伙伴在吐槽
  1. else if (year == known_year)//不懂 { if (month > 2) { leap_year_count = 1;//為什么這里要等于1,之前不是判斷過輸入1901要求重新輸入嗎 }, }
    坤坤2018-04-10 10:17 回復(fù)
    • 二月是一個(gè)特殊年,如果月份超過了需要用一個(gè)方法去判斷當(dāng)前年份二月的天數(shù)
      2021-11-03 19:08 回復(fù)
  2. vs出錯(cuò)
    sss2019-01-24 21:22 回復(fù)