Sunday, 26 August 2012

Calendar


/* Restriction:-Any year after 1980.*/
#include <stdio.h>
#include <stdlib.h>
void main()
{
   char*days[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
   char*month1[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
   int d_c,l,year,day=0,year2,space;
   printf("Enter the year\n");
   scanf("%d",&year);
   year2=year,d_c=3;
   year=year-1980;
   l=year%4==0?year/4:year/4+1;
   year=year-l;
   year+=(l*2);
   d_c+=(year%7);
   if(d_c>7)
   d_c-=7;
   for(l=1;l<=12;l++)
   {
      printf("\n\t  %s\n",month1[l-1]);
      for(day=0;day<7;day++)
      printf("%s ",days[day]);
      printf("\n");
      space=(d_c-1)*4;
      while(space>0)
      {
         printf(" ");
         space--;
      }
      if(l==1||l==3||l==5||l==7||l==8||l==10||l==12)
        day=31;
      else if(l==4||l==6||l==9||l==11)
        day=30;
      else if(l==2)
      {
         if(year2%(year2%100==0?400:4)==0)
           day=29;
         else
           day=28;
      }
     for(year=1;year<=day;year++)
     {
      if(year/10==0)
       printf(" %d  ",year);
      else
       printf("%d  ",year);
      d_c++;
      if(d_c>7)
      {
        d_c=1;
        printf("\n");
      }
     }
    printf("\n");
   }
   system("pause");
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
@Gnosioware Solutions