0% found this document useful (0 votes)
127 views17 pages

Calender

The document describes a C program that generates a calendar for a given year. It takes user input for the year and uses algorithms to determine the day of the week for January 1st and whether the year is a leap year. It stores month names and number of days in each month in arrays. The calendar function prints the calendar with the days of the week and dates formatted in a grid. It uses loops to iterate through months and days, and conditional statements to handle leap years and calculate weekday positions correctly. The program provides a simple way to generate and view calendars without external libraries.

Uploaded by

vidhatekaruna4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views17 pages

Calender

The document describes a C program that generates a calendar for a given year. It takes user input for the year and uses algorithms to determine the day of the week for January 1st and whether the year is a leap year. It stores month names and number of days in each month in arrays. The calendar function prints the calendar with the days of the week and dates formatted in a grid. It uses loops to iterate through months and days, and conditional statements to handle leap years and calculate weekday positions correctly. The program provides a simple way to generate and view calendars without external libraries.

Uploaded by

vidhatekaruna4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

MAHARASHTRA STATE BOARD OF TECHNICAL

EDUCATION

NAVJEEVAN EDUCATION SOCIETY’S POLYTECHNIC

BHANDUP(W)

MICRO PROJECT

Title of Microproject: Academic Calender


ACADEMIC YEAR 2022-2023
Subject: Programing in C (22226)
MAHARASHTRASTATEBOARDOF TECHNICAL
EDUCATIONCERTIFICATE

This is certify to. 1133, 1134, 1135, 1136 .SECOUNDSemesterof


diploma inCOMPUTER ENGINEERING (CO) , of institute
NAVJEEVAN EDUCATION SOCIETY’SPOLYTECHNIC (Code: 0144)
has completed the project work satisfactorily in Subject:Programing in C
(22226)for the academic year 2022 to 2023 as prescribedthe in
curriculum.
Place: Bhandup Date:

Subject Teacher Principal Head of department


AJAY Sudhakar
Mahesh
BHOIR Bharambe
pimpalkar

Seal of Institute
Branch:COMPUTER ENGINEERING
Name of Microproject:Academic Calender
Academic Calender
Part A

1. Introduction:
This program is a calendar program written in C language. It takes input of
a year from the user and determines the day code for the first day of that year using the
Sakamoto's Algorithm. It then determines if the year is a leap year or not, and adjusts
the number of days in February accordingly. Finally, it displays a calendar for the entire
year, showing all the months and their corresponding dates. The calendar is displayed
on the console with the days of the week arranged in columns, starting from Sunday and
ending on Saturday. The program makes use of arrays to store the number of days in
each month and the names of the months. It also uses loops to iterate through the
months and days of each month, and conditional statements to determine the correct
position of each date on the calendar. Overall, this program can be a useful tool for
displaying a yearly calendar in a clear and concise format.

Aim of the Microproject:


1. The aim of this calendar program is to display a calendar for a given year,
showing the days of the week for each month.
2. The program determines the day code for the first day of the year, whether the
year is a leap year or not, and then prints out a calendar for each month of the
year, including the days of the week and the dates for each day.
3. The user is prompted to enter a year, and the program uses this year as input for
generating the calendar.
4. The output is a neatly formatted calendar that can be printed out and used for
planning or scheduling events.

Resources Required:
Sr. Name of Resource Suggested Broad Specification Quantity No

1.

2.

3.

4.

5.

6.
PartB

BRIEF INTRODUCTION
:-
The aim of this calendar program is to display a calendar for a given year,
showing the days of the week for each month.
The program determines the day
code for the first day of the year, whether the year is a leap year or not, and then
prints out a calendar for each month of the year, including the days of the week
and the dates for each day. The user is prompted to enter a year, and the program
uses this year as input for generating the calendar. The output is a neatly
formatted calendar that can be printed out and used for planning or scheduling
events.
Input:

#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 inputye
ar(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 \n"
Sat);

// 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:
Explanation:
To begin, we'll create two arrays: one with the number of days in each month, and
another with all of the month
es.nam
Note that the first position in both arrays is
intentionally left empty; we want to keep things simple by using 1 to 12.

The user input is obtained via the first inputyear


function ).(The user is asked to enter a
year. Note that no input validation
errororhandling is done in order to keep things
basic.

The following method,determinedaycode), is( used to get the day number of the first
day of that year, allowing us to display the date in the proper location. (As a result, it's
just utilized for outp
ut.)

Thedetermineleapyear ) method
( is used to see whether the user's input is a leap year. If
this is the case, the number of days in February is increased to 29.

Each month is printed on the screen using the final function calendar(). To loop across
all months, use the first for loop. The month's name and all of the days of the week are
then printed. The daycode is then used to place the prompt under the correct weekday.
Then we print a month's worth of dates. The final step is to place the
e prompt in th
proper weekday position.

You might also like