forked from SR-Sunny-Raj/Hacktoberfest2021-DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.c
58 lines (50 loc) · 1.27 KB
/
calendar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* A program to take an input year from the user
* And display that year's :- Calender using user defined function in c.
*/
#include <stdio.h>
/*User defined function*/
void gotoxy(int x,int y)
{
while(y--)printf("\n");
while(x--)printf(" ");
}
/*The month handle function*/
void printmonth(int day,int start)
{
gotoxy(5,0);
printf(" S M T W T F S");
gotoxy(10,2);
for(int i=1;i<start;i++)printf(" ");
for(int i=1;i<=day;i++){
printf("%3d",i);
if((i-1+start)%7==0){printf("\n");gotoxy(10,0);}
}
gotoxy(0,3);
}
/*The driver code*/
int main(void)
{
int year,start=2,day[]={31,28,31,30,31,30,31,31,30,31,30,31};
char name[][4]={"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
/*Taking input from the user*/
printf("Enter Year\n");
scanf("%d",&year);
/*Algorithm*/
if((year%400)==0) day[1]=29;
else if((year%100)==0) day[1]=28;
else if((year%4)==0) day[1]=29;
year--;
start=(start+year)%7;
start+=(year/4)-(year/100)+(year/400);
start%=7;
gotoxy(0,3);
/*Incrementor*/
for(int i=0;i<12;i++)
{
printf("%5s",name[i]);
printmonth(day[i],start);
start=(start+day[i]-1)%7+1;
}
gotoxy(0,15);
return 0;
}