0% found this document useful (0 votes)
76 views3 pages

Calender

The document describes a C program to create a calendar application. It includes an algorithm that allows the user to navigate between months and years using arrow keys, insert new months/years, print the calendar, and exit. The program code defines arrays for days in each month and month names. It gets the year from the user, calculates the day of the week for January 1st, checks if it's a leap year, and prints the calendar grid for the full year.

Uploaded by

Darwin V
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
76 views3 pages

Calender

The document describes a C program to create a calendar application. It includes an algorithm that allows the user to navigate between months and years using arrow keys, insert new months/years, print the calendar, and exit. The program code defines arrays for days in each month and month names. It gets the year from the user, calculates the day of the week for January 1st, checks if it's a leap year, and prints the calendar grid for the full year.

Uploaded by

Darwin V
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

CALENDER USING C

AIM :
To create a calender application using c

ALGORITHM:
A C program which accepts any month-year and
displays calendar of that month. We'll add more features
like, if user press:

● Left-arrow key - go to the previous month.


● Right-arrow key - go to the next month.
● Up-arrow key - go to the next year.
● Down-arrow key - go to the previous year.
● I - insert new month year.
● P - print the month in a text file.
● Esc - exit the program.

PROGRAM:
#include<stdio.h>
#define TRUE 1
#define FALSE 0

int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *months[]=
{
" ",
"\n\n\nJanuary",
"\n\n\nFebruary",
"\n\n\nMarch",
"\n\n\nApril",
"\n\n\nMay",
"\n\n\nJune",
"\n\n\nJuly",
"\n\n\nAugust",
"\n\n\nSeptember",
"\n\n\nOctober",
"\n\n\nNovember",
"\n\n\nDecember"
};
int inputyear(void)
{
int year;

printf("Please enter a year (example: 1999) : ");


scanf("%d", &year);
return year;
}

int determinedaycode(int year)


{
int daycode;
int d1, d2, d3;

d1 = (year - 1.)/ 4.0;


d2 = (year - 1.)/ 100.;
d3 = (year - 1.)/ 400.;
daycode = (year + d1 - d2 + d3) %7;
return daycode;
}

int determineleapyear(int year)


{
if(year% 4 == FALSE && year%100 != FALSE || year%400
== FALSE)
{
days_in_month[2] = 29;
return TRUE;
}
else
{
days_in_month[2] = 28;
return FALSE;
}
}

void calendar(int year, int daycode)


{
int month, day;
for ( month = 1; month <= 12; month++ )
{
printf("%s", months[month]);
printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" );
// Correct the position for the first date
for ( day = 1; day <= 1 + daycode * 5; day++ )
{
printf(" ");
}

// Print all the dates for one month


for ( day = 1; day <= days_in_month[month]; day++
)
{
printf("%2d", day );

// Is day before Sat? Else start next line


Sun.
if ( ( day + daycode ) % 7 > 0 )
printf(" " );
else
printf("\n " );
}
// Set position for next month
daycode = ( daycode +
days_in_month[month] ) % 7;
}
}

int main(void)
{
int year, daycode, leapyear;

year = inputyear();
daycode = determinedaycode(year);
determineleapyear(year);
calendar(year, daycode);
printf("\n");
}
OUTPUT :

You might also like