Making a full project calendar app by C

We will make a calendar app by C language in this full project. This is a full projects using C programming language and you can use all the code for creating your own project.

Source code of calendar app by C

Let’s get started to write code for making a calendar app by C For making this calendar app project.

// making a calendar app by C language

#include <stdio.h>

int getFirstDayOfTheYear(int year){          // function for getting first day of the year
int day = (year*365 + ((year - 1) / 4) - ((year - 1) / 100) + ((year - 1) / 400)) % 7;
return day;
}

int main(){
    char *months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int i, j, totalDays, weekDay, spaceCounter = 0, year;
    printf("\nEnter your favorite year to see the calender: \n");
    scanf("%d", &year);

    printf("\n\n********************* Welcome to %d *********************", year);

    // For leap year, February will be in 29 days

    if (year % 4 == 0 && year % 100 != 0 || (year % 400 == 0)){
        daysInMonth[1] = 29;
    }

    // get first day of the year
    weekDay = getFirstDayOfTheYear(year);

    for (i = 0; i < 12; i++){
        printf("\n\n\n\n------------------------%s-------------------------\n", months[i]);
        printf("\n    Sun    Mon    Tue    Wed    Thu    Fri    Sat\n\n");

        for(spaceCounter = 1; spaceCounter <= weekDay; spaceCounter++){
            printf("       ");     // printing 7 space for every blank day in a month
        }
        totalDays = daysInMonth[i];
        for ( j = 1; j <= totalDays; j++){
            printf("%7d", j);        // 7d will print the day with 7 space
            weekDay++;
            if( weekDay > 6){
                weekDay = 0;
                printf("\n");
            }
        }
    }

return 0;
}

Give the input that which year you want to see the calendar like as following. Then press the enter.

Enter your favorite year to see the calender:
2020

Output of calendar app program:

making a calendar app full project by c programming