Calendario gregoriano en lenguaje C
int semana(int y, int m, int d);
void main()
{
int mes día[12]= {31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31};
int y, w, I, m= 1, d = 1;
Printf("Ingrese el año yyyy:\ n ");
scanf("%d ", & ampy
<); p >if(y % 4 = = 0 & & ampy%100!= 0)mes día[1]= 29;for(m = 1; m & lt=12;m++) p>
{
Printf("\n %d año, %d mes\n ", y, m);
printf(" S M T w T F S \ n " );
for(d = 1; d & lt= mes día[m-1]; d++)
{
w = semana(y , m, d);
if (d==1)
{
for(I = 0;i<w;i++)printf(" ");
}
if(d & lt;10) printf("%d ", d);
si no printf("%d " , d) ;
if(w = = 6)printf(" \ n ");
}
}
}
int semana (int y, int m, int d)
{
int w;
if((m== 1)| |(m==2))
{
y-;
m+= 12;
} p>
w =(d+2 * m+3 *(m+1)/5+y+y/4-y/10y/401)% 7;
Retorno (w );
}
Los resultados de la operación son los siguientes:
Ingrese el año yyyy:
2001
2001, enero
S M T w V F S
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
2001, febrero
S M T w V F S
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
2001, marzo
S M T w V F S
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
2001, abril
S M T w V F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14 p>
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
2001, mayo
S M T w T F S
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
2001, junio
S M T w V F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23 p >
24 25 26 27 28 29 30
2001, julio
S M T w V F S
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
2001, agosto
S M T w V F S
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
2001, septiembre
S M T w T F S
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
Octubre 2001
S M T w V F S
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
Noviembre 2001
S M T w V F S
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
2001, 65438+febrero
S M T w V F S
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 Por favor presione cualquier tecla para continuar... p>