#include<stdio.h>
/*Taking a 7row and 7column array for each month*/
int calendar(int ar[7][7],int i,int j,int b,int c,int yc,int y){
if(yc==y){
switch(b){
case 1:
printf(" \n__________________\n*JANUARY_%d\n",y);
break;
case 2:
printf(" \n__________________\n*JANUARY_%d\n",y);
break;
case 3:
printf("\n__________________\n*MARCH_%d\n",y);
break;
case 4:
printf("\n__________________\n*APRIL_%d\n",y);
break;
case 5:
printf("\n__________________\n*MAY_%d\n",y);
break;
case 6:
printf("\n__________________\n*JUNE_%d\n",y);
break;
case 7:
printf("\n__________________\n*JULY_%d\n",y);
break;
case 8:
printf("\n__________________\n*AUGUST_%d\n",y);
break;
case 9:
printf("\n__________________\n*SEPTEMBER_%d\n",y);
break;
case 10:
printf("\n__________________\n*OCTOBER_%d\n",y);
break;
case 11:
printf("\n__________________\n*NOVEMBER_%d\n",y);
break;
case 12:
printf("\n__________________\n*DECEMBER_%d*\n",y);
break;
}
printf("Su M T W Th F Sa \n_________________________________________\n");
}
/*second section*/
j=j%7;
int l=31;
if(c==500){
printf("End");
return 0;}
if(b==2 && ((yc-1900)%4==0 || (yc-2000)%4==0 )){l=29;}
if(b==2 && ((yc-1900)%4!=0 || (yc-2000)%4!=0 )){l=28;}
if( b==4 || b==6 || b==9 || b==11 ){l=30;}
int n=1;
for(i=0;i<7;i++){
while(n<=l){
if(j==7){j=0;break;}
ar[i][j]=n;
n++;
j++;
}
}
int k=j%7;
if(yc==y){
printf("\n");
for(i=0;i<7;i++){
for(j=0;j<7;j++){
if( ar[i][j]==0 ){
printf(" "); }
else {
if( ar[i][j]>0&&
ar[i][j]<10 ){
printf("%d ",ar[i][j]);
}
else{
printf("%d ",ar[i][j]);
}
if(j==6){printf("\n");}
}
}
}
}
for(i=0;i<7;i++){
for(j=0;j<7;j++){ar[i][j]=0;}
}
j=k;
b++;
if(b>12){b=1;
yc++;}
/*recursive call*/
calendar( ar,i,j,b,c+1,yc,y);
}
/*
yc=year counter,
y=year
b=month counter
l=number of days in the month.
*/
int mo[7][7];
int year;
int main(){
printf("PLANNER CALENDAR\n\n");
printf("Enter Year in range [1994,2025]: ");
scanf("%d",&year);
calendar(mo,0,6,1,1,1994,year);
}
0 Comments