Translate

Labels

Saturday 16 March 2013

CALENDER IN C

MAKING A CALENDER FOR GIVEN YEAR.

#include<stdio.h>
void day(int,int,int);
char days[7][10]={"saturday","sunday","monday","tuesday","wednessday",
"thursday","friday"};
int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void main()
{
char month[12][15]={"January","Febrauary","March","April","May","June",
"July","August","September","October","November","December"};
static int d,m,tdays,i,t1,t2,y,count=0,prnt=0;
clrscr();
printf("\t\t    THE DAY OF GIVEN DATE, MONTH & YEAR\n");
printf("\t\t\tCALENDER FOR THE GIVEN YEAR\n");
printf("\n\nEnter the date, month & year:\n");
scanf("%d%d%d",&d,&m,&y);
day(d,m,y);
printf("\n\n\nPress any key for printing the %d calender.\n",y);
getch();
for(m=1;m<=12;m++)
{
if(y%4==0) mon[1]=29;
for(i=0;i<m-1;i++) t1+=mon[i];
tdays=(365*(y-1)+t1+(y/4)+1);
t2=tdays%7;
clrscr();
printf("\n\n\n                           %s  %d\n",month[m-1],y);
printf("\n     sun     mon     tue     wed     thu     fri     sat\n\n");
if (t2==0) t2=7;
for(i=1;i<t2;i++)
{
printf("        ");
count++;
}
while(prnt<mon[m-1])
{
if (count==7)
{
printf("\n\n");
count=0;
}
printf("%8d",++prnt);
count++;
}
getch();
t1=0;
count=0;
prnt=0;
}
}
void day(int d,int m,int y)
{
static int t1,tdays,i,t2;
if(y%4==0) mon[1]=29;
for(i=0;i<m-1;i++) t1+=mon[i];
tdays=(365*(y-1)+t1+(y/4)+d);
t2=tdays%7;
printf("\nThe given day is... %s",days[t2]);
}

No comments: