C > Beginners Lab Assignments
Calender Program in C
Calender Program in C //Program to display calender for a given year #include
#include
#include
#include
unsigned long days=0; //stores the days elapsed since 01.01.1899 void display(int n) //contains the number of days to display { int i, column, k, flag=0, j; printf("Sun Mon Tues Wed Thur Fri Sat "); for(i=1; i<=n; i++) { k=days%7;//remainder gives the starting day of each month if(flag==0) { for(j=1; j<=k; j++)//controls tabs of first week printf(" "); flag=1;//ensures that block is only executed once column=k; } printf("%d ", i); column++; if(column%7==0)//prints new line at the end of each week printf(" "); } printf(" Press any key to continue "); getch(); } void calculate(int year) //function calculates no. of days elapsed since 1899 { int i, month; for(i=1899; i
'9')//checks for invalid inputs { printf(" Invalid Year!"); printf(" END OF PROGRAM"); getch(); exit(0); } year = atoi(ch); //converts the year from string to integer datatype clrscr(); printf(" Calender for Year %d", year); printf(" ********************** "); calculate(year); //calls function to calculate no. of days elapsed printf(" ******************************************* "); printf(" Press 1 to continue, 2 to exit "); scanf("%d", &choice); }while(choice==1); clrscr(); printf(" END OF PROGRAM"); getch(); }
C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting