Finding the day of 1 Jan of any year from 2001 : C Program

According to Gregorian Calender, it was Monday on the date 01/01/2001. If any year is input through the keyboard write a program to find out what is the day on 1st January of this year.


There are also many other ways do to it but now I am sharing the first one that I find, I will share you another algo’s for it in upcoming posts.

Solution : C Program


#include <stdio.h>

int main()
{
    int year, days, leap_year, year_diff, day;
   
    printf(“Enter year:”);
    scanf(“%d”, &year);
   
    year_diff = (year – 2001);
    leap_year = (year_diff/4);
   
    day = (2 + year_diff + leap_year);
    day = (day % 7);
   
    if (day == 1)
       printf(“It will be Sunday on 1 Jan of %d”, year);
    
    else if (day == 2)
       printf(“It will be Monday on 1 Jan of %d”, year);
      
    else if (day == 3)
       printf(“It will be Tuesday on 1 Jan of %d”, year);
     
    else if (day == 4)
       printf(“It will be Wednesday on 1 Jan of %d”, year);
      
    else if (day == 5)
       printf(“It will be Thursday on 1 Jan of %d”, year);
      
    else if (day == 6)
       printf(“It will be Friday on 1 Jan of %d”, year);
      
    else if (day == 7)
       printf(“It will be Saturday of 1 Jan of %d”, year);
     
    else
       printf(“I think there is some error. Please try again!”);
      
      
    return 0;
   
}

Leave a comment

Design a site like this with WordPress.com
Get started