/****************************************************************************/
/* Calendario gregoriano perpetuo.                                          */
/*                                                                          */
/* Jaime Suarez <mcripto@bigfoot.com> 2003                                  */
/* en http://elparaiso.mat.uned.es                                            */
/****************************************************************************/

#include <stdio.h>

int diasemana(int,int,int);

main()
{
	char *dsem[7]={"domingo", "lunes","martes","miércoles","jueves","viernes",
	"sábado"};
	int d,m,y,w;

	printf("Dia(1-31) : "); scanf("%d",&d);
	printf("Mes(1-12) : "); scanf("%d",&m);
	printf("Año(nnnn) : "); scanf("%d",&y);

	w=diasemana(d,m,y);
	printf("El %d-%d-%d  cae en  %s.\n", d,m,y,dsem[w]);
	return 0;
}

int diasemana(int d, int m, int y)
{
	int w,c,dia,mes,anno;

	dia=d;
	if (m<3) { anno=(y-1)%100; c=(y-1)/100; mes=m+10; }
	else { anno=y%100; c=y/100; mes=m-2; }

	w=(dia+ (int)(2.6*mes-0.2) -2*c +anno +anno/4 +c/4) %7;
	if (w<0) w+=7;
	return w;
}