Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- int firstday = 1 ;
- int year=0;
- int Febuary=0;
- char *weekdays[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
- char *months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",};
- void prtspace(int first)
- {
- int i ;
- for(i=0;i<first%7;i++)
- printf(" ");
- }
- int firstcal(int y)
- {
- int i;
- y = y-1900;
- int flag=0;
- for(i=1;i<=y;i++)
- {
- flag += (!(i%4) && i%100 || !(i%400))? 366 : 365 ;
- //printf("=%d %d=\n",i,flag%365);
- }
- firstday = (firstday+flag)%7;
- return firstday;
- }
- void leapjudge(int y)
- {
- if(!(y%400) || (y%100) && !(y%4))
- {
- Febuary = 29 ;
- printf("This year %d is leap year\n",y);
- }
- else
- {
- Febuary = 28;
- printf("This year %d is not leap year\n",y);
- }
- }
- int main(int argc, char *argv[])
- {
- int i,j;
- int k;
- int Days[12] = {31,Febuary,31,30,31,30,31,31,30,31,30,31};
- printf("A calender of which year :");
- scanf("%d",&year);
- //閏年二月日數
- leapjudge(year);
- //該年一月的空白日數
- firstcal(year);
- for(i=0;i<12;i++)
- {
- printf("%d\n",Days[i]);
- printf("\t%4s\n",*(months+ i));
- for(k=0;k<7;k++)
- {
- printf("%4s",*(weekdays+ k));
- }
- printf("\n");
- prtspace(firstday);
- for(j=1;j<=Days[i];j++)
- {
- printf(" %3d",j);
- firstday = (++firstday)%7;
- if(!firstday)
- printf("\n");
- }
- printf("\n");
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment