【视频】某一年日历的实现 实例9-大学计算机完美攻略
PPT
视频
源代码
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
int main()
{
int a[13] = { 0傅莹简历,31,28本·华莱士 ,31,30青瓜炒蛋,31打靶归来简谱,30,31丞相如此多娇 ,31汖怎么读 ,30喀秋莎简谱,31经视故事会,30桂公府 ,31 };
int i, j恶魔恋爱啦 , num, q他是偏执狂 ,吴锡豪 year, day;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE)军人机密, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
printf("请输入1900年以后的年份:");
while (scanf("%d", &year) 华子岗!劳技课教案= EOF)
{
int mark = 1;
for (i = 1900; i<year; i++)
{
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)
day = 366;
else
day = 365;
mark = (mark + day) % 7;
}
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
a[2] = 29;
else
a[2] = 28;
for (i = 1; i<13; i++)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE)奥尔布莱特 , FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
{printf("****************%d月****************\n"周开开 , i); }
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_INTENSITY);
{printf("日\t一\t二\t三\t四\t五\t六\n"); }
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
num = 1;
for (q = 0; q<mark; q++)
printf(" \t");
for (q = mark; q<7; q++)
printf("%d\t"浩劫妙冤家 , num++);
printf("\n");
while (num <= a[i])
{
for (j = 0; j<7; j++)
{
if (num <= a[i])
printf("%d\t", num++), mark = (j + 1) % 7;
}
printf("\n");
}
printf("\n");
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
printf(" ########by:回车键########\n");
}
return 0;
}
小编寄语
在实现一年日历的时候我们其实可以使用更多的技巧使得程序更加高效,大家可以在算法上面多下功夫。