Home   Easy-Code    Forum  Updater 
Twitter Facebook



Calender using c graphics

Critics Rating:

Users Rating:



#include <stdio.h>

#include <graphics.h>

void main()

{

int gd=0,gm=0,t1,t2,i,j,l=0,dd=1,mm,yy,y,k,a,b,c,d;

char yy1[4];

char *mdays[]={"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"};

char *day[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

char *wkday[]={"Sun","Monday","Tuesday","Wednesday","Friday","Saturday"};

char *mon[]={"January","February","March","April","May","June","July","August","September","October","November","December"};

char week[10];

initgraph(&gd,&gm," ");

cleardevice();

printf("Enter month & year (mm,yyyy)\n");

scanf("%d%d",&mm,&yy);

k=((yy-1)/100)%4;

if (k==1) y=5;

else if (k==2) y=3;

else if (k==3) y=1;

else if (k==0) y=0;

a=(yy-1)%100;

b=((a/4*2)+(a-(a/4)))%7;

c=(int)(30.42*(mm-1))+dd;

if (mm==2) c++;

if (mm>2 && mm<8) c--;

d=(y+b+c)%7;

cleardevice();

printf("\t1/%d/%d is %s",mm,yy,wkday[d]);

strcpy(week,wkday[d]);

itoa(yy,yy1,10);

strcpy(yy,yy1);

settextstyle(3,0,6);

outtextxy(150,50,mon[mm-1]);

outtextxy(400,50,yy1);

settextstyle(1,0,4);

for(i=0,j=0;j<=240;j+=40,i++)

{

outtextxy(150,160+j,day[i]);

if (strncmp(day[i],week,3)==0)

t2=160+j;

}

rectangle(15,15,625,465);

for(i=0;i<=240;i+=40)

   for(j=0;j<=250;j+=50)

   rectangle(240+j,160+i,290+j,200+i);

if (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12)

t1=31;

else

if (mm==4 || mm==6 || mm==9 || mm==11)

t1=30;

else

if (mm==2)

{

if ((yy%100)%4==0)

t1=29;

else

t1=28;

}

settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);

l=0;

for(i=0;i<=250;i+=50)

{

   for(j=0;j<=240;j+=40)

   {

if (l>=t1)

   break;

   if (l==0)

   {

   outtextxy(250+i,t2+j,"1");

   l++;

   }

   else

   {

   outtextxy(250+i,t2+j,mdays[l++]);

   if ((t2+j)==400)

   {

   j=241;

   t2=160;

   }

   }

   }

}

getch();

closegraph();

return;

}

Courtesy, Source, References & Regards: Kishore AVGK

While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright@2009-2011 by KuGuNi.com. All Rights Reserved.