Printing Calendar in C Program Part 1


#include<stdio.h>
#include<conio.h>
void print(int,int,int,int);
static char *months[]={"January","february",
"march","april","may","june","july","augest",
"september","october","november","december"};
void main()
{
    int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    int y,m,d=1,ny,nhy,noy,tonhy,nl,no,tonlno,i,tmd=0,
	fiod,seod,odd;
    clrscr();
    printf("\Enter the year :");
    scanf("%d",&y);
    printf("\nEnter the month :");  //www.tutorjoes.com
    scanf("%d",&m);
    y=y-1;
    ny=y-1600;
    nhy=ny/100;
    if(nhy==4||nhy==8||nhy==12||nhy==16)
    {
       tonhy=(nhy*5)+1;
    }
    noy=ny%100;
    tonhy=nhy*5;
    nl=noy/4;
    no=noy-nl;
    tonlno=(nl*2)+no;
    fiod=tonhy+tonlno;
    fiod=fiod%7;
    if(y+1%4==0)
    {
       mon[1]=29;
    }
    for(i=0;i<=m-2;i++)
    {
       tmd=tmd+mon[i];   //www.tutorjoes.com
    }
    tmd=tmd+d;
    seod=tmd%7;
    odd=fiod+seod;
    if(odd>7)
    {
      odd=odd%7;
    }
    print(y,m,mon[m-1],odd*5);
}
void print(int y,int m, int li,int o)
{
    int i,c=o+20,r=11;
    clrscr();      //www.tutorjoes.com
    gotoxy(28,6);
    printf("%s     %d",months[m-1],y+1);
    gotoxy(20,9);
    printf("Sun  mon  thu  wed  thu  fri  sat");
    for(i=1;i<=li;i++)
    {
       gotoxy(c,r);
       printf("%d",i);
       c=c+5;
       if(c>=55)
       {
	 r=r+2;
	 c=20;
       }

    }
   getch();
}

Login To Download Source Code

Leave a Comment:

Login To Comment

List Of Programs


Goto Examples

Operators

Looping

Number Conversion

Pattern Design

Arrays

Matrix Examples

Sorting Examples

String Function

Change Case

String In C

Maths Functions

User Defined Functions

Recursive Functions

Pointer

Structure

File Concept

Calender Programming