Skip to content
October 25, 2007 / ranacse05

Any year Calendar


Here is the C code for Any year Calendar its v1.0.Just copy the code and past and then use Turbo C to compile it.

CODE:

#include “stdio.h”
#include “conio.h”

int d[12][5][7]={0};

//for print

void pr(char *m,int a)
{int l,j,i;
char day[21]={“sa su mo tu we th fr”};

printf(“%s”,m);
for(l=0;l<3;l++)
printf(” %s “,day);
printf(“\n\n”);
for(i=0;i<5;i++)
{ for(j=0;j<7;j++)
printf(“%3d”,d[a+0][i][j]);
if(j%7==0)
{printf(” “);
for(j=0;j<7;j++)
printf(“%3d”,d[a+1][i][j]);
if(j%7==0)
{printf(” “);
for(j=0;j<7;j++)
printf(“%3d”,d[a+2][i][j]);}

printf(“\n\n”);}
}
printf(“\n\n”);getch();
}
//————————————————————————–

void main()
{
int i,xl,k,l,j,a,m,x,y,z,g,c,y1=0,M=0,b=0,Y,C,flag;

char *m1={“\tJANUARY\t\t\tFEBRUARY\t\tMARCH\n\n”};
char *m2={“\tAPRIL\t\t\t MAY\t\t\t JUN\n\n”};
char *m3={“\tJULY\t\t\tAUGUST\t\t\tSEPTEMBER\n\n”};
char *m4={“\tOCTOBER\t\t\tNOVEMBER\t\tDECEMBER\n\n”};

clrscr();
printf(“Please Enter Year:”);
scanf(“%d”,&y1);

Y=(y1-1)%100;
C=(y1-1)/100;
x=(2.6*11-.02)+1+Y+(Y/4)+(C/4)-2*C;
x=x%7;
x=(x+1)%7;

xl=0;
flag=0;

for(k=0;k<12;k++)
{
a=1;
for(j=x;j<7;j++)
d[k][0][j]=a++;

if(flag==1)
d[k][0][0]=0;

flag=0;
if((k==0)||(k==2)||(k==4)||(k==6)||(k==7)||(k==9)||(k==11))
{
if(x==5)
{d[k][0][0]=31;flag=1;}
if(x==6)
{
d[k][0][0]=30;d[k][0][1]=31;flag=1;
}
}
else if( (x==6) && ((k==3)||(k==5)||(k==8)||(k==10)) )
{ d[k][0][0]=30;flag=1;}

for(i=1;i<4;i++)
for(j=0;j<7;j++)
d[k][i][j]=a++;

if((k==0)||(k==2)||(k==4)||(k==6)||(k==7)||(k==9)||(k==11))
b=31;
else if((k==3)||(k==5)||(k==8)||(k==10))
b=30;
else if(k==1)
{if((y1%4==0)||((y1%100!=0)&&(y1%400==0)))
b=29;
else
b=28;
}

for(j=0;a<=b;j++)
d[k][4][j]=a++;

x=j%7;

}

getch();
clrscr();
for(i=0;i<33;i++)
printf(” “);
printf(“%d”,y1);
for(i=37;i<80;i++)
printf(” “);
printf(“\n\n”);

pr(m1,0);
pr(m2,3);
pr(m3,6);
pr(m4,9);

getch();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: