hi friends this is my code ............
IF ANY ONE FINDS ANY BUGS PLEASE INFORM ME...........
/*THIS PROGRAM IS TO SHOW THE CALENDER OF A SPECIFIC MONTH//
DEVELOPED BY:R.KANNAN
DATE CREATED & MODIFIED:09/08/2008
13/08/2008*/
cpp
#include<stdio.h>
#include<conio.h>
void printtab()
{
printf("\t\t\t");
}
int noofleaps(int year)
{
return(year>2008?((year-2009)/4+1)
(2008-year)/4));
}
char *monthname(int m)
{
switch(m)
{
case 1:
return "JAN";
case 2:
return "FEB";
case 3:
return "MAR";
case 4:
return "APR";
case 5:
return "MAY";
case 6:
return "JUN";
case 7:
return "JUL";
case 8:
return "AUG";
case 9:
return "SEPT";
case 10:
return "OCT";
case 11:
return "NOV";
case 12:
return "DEC";
}
}
int noofdays(int m,int y)
{
switch(m)
{
case 1:
return 31;
case 2:
return((!(y%4))?29:28);
case 3:
return 31;
case 4:
return 30;
case 5:
return 31;
case 6:
return 30;
case 7:
return 31;
case 8:
return 31;
case 9:
return 30;
case 10:
return 31;
case 11:
return 30;
case 12:
return 31;
}
}
int monval(m)//to find the month value based on which the starting
{ //day of the month will be caluculated
switch(m)
{
case 1:
case 10:
return 0;
case 2:
case 3:
case 11:
return 3;
case 4:
return 6;
case 5:
return 1;
case 6:
return 4;
case 7:
return 6;
case 8:
return 2;
case 9:
case 12:
return 5;
}
}
int main()
{
int yearst,monst,year=1,mon=1,i=0,j,k;
char ch,*days[7]={"sun","mon","tue","wed","thu","fri","sat"};
clrscr();
printf("______________________________________\n");
printf("*THIS PROGRAM IS TO SHOW THE CALENDER*\n");
printf("______________________________________\n");
do
{
yearst=monst=i=j=k=0;
year=mon=0;
printf("ENTER A MONTH IN NUMBER,\n1.jan\t4.apr\t7.jul\t10.oct\n\
2.feb\t5.may\t8.aug\t11.nov\n\
3.mar\t6.jun\t9.sep\t12.dec\nenter the respective no.:");
while(!mon)
{
i=scanf("%d",&mon);
if(!i||(mon>12||mon<1))
{
printf("enter month from 1 to 12:");
fflush(stdin);
mon=0;
}
}
printf("enter the year:");
while(!year)
{
if(!scanf("%d",&year))
{
printf("enter valid year:");
year=0;
fflush(stdin);
}
else
break;
}
if(year>2008)
yearst=2+((year-2008)+noofleaps(year))%7;
else
{
yearst=2+(7-((2008-year)+noofleaps(year))%7)%7;
}
monst=(yearst+1+monval(mon)+((!(year%4))?1:0)*(mon>2?1:0))%7-1;
monst%=7;
printtab();
printf("\t%s of the year %d\n",monthname(mon),year);
printtab();
for(i=0;i<=6;i++)
printf("%s\t",days);
printf("\n");
printtab();
for(i=0;i<monst;i++)
printf(" \t");
k=noofdays(mon,year);
j=1;
while(k)
{
printf("%02.0d\t",j);
if(!((i+1)%7))
{
printf("\n");
printtab();
}
j++;
k--;
i++;
}
printf("\nDo you wanna use this to see another month (Y/N)?");
}while((ch=getch())=='y'||ch=='Y');
return 0;
}
Mod edit: Please
[code
] Please paste your code between these tags
[/code
] Thanks, gabehabe