本文实例为大家分享了C语言实现万年历程序,供大家参考,具体内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include <stdio.h> int year( int y) { if ((y%4==0) && (y%100!=0) || y%400==0) return 366; else return 365; } int main() { int y; int i,j,sum=0; int begin,week; int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; scanf ( "%d" ,&y); for (i=1;i<y;i++) sum+=year(i); week=(sum+1)%7; //表示该年1月1日为星期几 if (year(y)==366) days[1]=29; printf ( "\n%d年日历如下:\n\n" ,y); for (i=0;i<12;i++) { printf ( " %d月 \n" ,i+1); printf ( " 7 1 2 3 4 5 6\n" ); printf ( "=====================\n" ); begin=1; for (j=0;j<week;j++) printf ( " " ); while (begin<=days[i]) { printf ( "%3d" ,begin); begin++; week=(week+1)%7; if (week%7==0) printf ( "\n" ); } printf ( "\n\n" ); } return 0; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/softwareldu/article/details/40475497