Welcome to the World of Programming

Welcome to the World of Programming

Search this blog

Calender Program::

:::Calender :::
make your own Calender using simple C Program..
__________

#include"stdio.h"
#include"dos.h"
#include"conio.h"
void calender();
int getkey();
int m,y,i;
void main()
{
int ch;
clrscr();
gotoxy(20,8);
printf("Enter month & year::");
scanf("%d %d",&m,&y);
calender();
while(1)
{
ch=getkey();
switch(ch)
{
case 72:
y+=1;
break;
case 80:
y-=1;
break;
case 75:
if(m==1)
{
m=12;y-=1;
}
else
m--;
break;
case 77:
if(m==12)
{
m=1;y+=1;
}
else
m++;
break;
case 1:
exit();
}
calender();
}
}


void calender()
{
char far *p=(char far *)0XB8000000;
char *month[]={"January","February","March","April","May","June","July","August","Septmber","October","November","December"};
int days[]={31,0,31,30,31,30,31,31,30,31,30,31};
int ld,s,c,r,d;
long int nd,td,fd;
clrscr();
for(i=3*160+13*2+1,c=0;i<=18*160+56*2+1;i+=2)
{
*(p+i)=112+4;
c++;
if(c==43)
{
i+=74;c=0;
}
}
for(i=4*160+29*2+1;i<=4*160+50*2+1;i+=2)
*(p+i)=5+112;
for(i=9*160+16*2+1,c=0;i<=17*160+54*2+1;i+=2)
{
*(p+i)=1+112;
c++;
if(c==34)
{
i+=92;c=0;
}
}
for(i=7*160+14*2+1;i<=7*160+54*2+1;i+=2)
*(p+i)=26;
nd=(y-1)*365L;
ld=(y-1)/4-(y-1)/100+(y-1)/400;
td=nd+ld;
if((y%400==0)||(y%100!=0&&y%4==0))
days[1]=29;
else
days[1]=28;
s=0;
for(i=0;i<=m-2;i++)
s=s+days[i];
td+=s;
fd=td%7;
c=16+fd*6; r=10;
gotoxy(30,5);printf("%s %d",month[m-1],y);
gotoxy(16,8);printf("Mon Tue Wed Thu Fri Sat Sun");
for(d=1;d<=days[m-1];d+=1)
{
gotoxy(c,r);
printf("%3d",d);
c=c+6;
if(c>52)
{
r+=2;c=16;
}
if(r>18)
r=10;
}
gotoxy(62,11);printf("Use arrow keys");
gotoxy(62,12);printf("for Nxt & Prv");
gotoxy(62,13);printf("month & year.");
gotoxy(63,16);printf("%c Nxt. year",30);
gotoxy(63,18);printf("%c Prv. year",31);
gotoxy(63,20);printf("%c Nxt. month",16);
gotoxy(63,22);printf("%c Prv. month",17);
for(i=15*160+62*2+1,c=0;i<=22*160+62*2+1;i+=2)
{
*(p+i)=112;
c++;
if(c==12)
{
c=0;i+=136+160;
}
}
}
int getkey()
{
union REGS i,o;
while(!kbhit());
i.h.ah=0;
int86(22,&i,&o);
return(o.h.ah);
}

_______________
steps to follow--

1.
run the program.
2. enter required month and year.
3. use arrow keys to go to the required month/year.
4. use "Esc" key to exit.



No comments:

Post a Comment