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

#include<stdio.h>  
int main()  
{  
    /*
      baseYear:- we start from the year 1 , we may also start from 1900 as it was MONDAY on Jan. 1 1900
	*/
    
	int baseYear = 1;
    
	int year, leap = 0, yearDiff, total_days = 0, day = 0;  
  
    printf("Enter a year : \n");  
    scanf("%d", &year);  
  
    yearDiff = year - baseYear;  
  
    while(baseYear < year)  
    {  
       
	    if((baseYear % 100!=0 && baseYear%4==0) || (baseYear%400==0))
	    {
		  leap++;  
		}
	
        baseYear++;
    }  
  
  
    total_days = (yearDiff - leap) * 365 + leap * 366;  
    day        = total_days % 7;  
  
    printf("\nThe day on 01 January %d was ", year);  
  
    switch(day)  
    {  
        case 0: 
				printf("Monday.\n");  
                break;  
        case 1: 
				printf("Tuesday.\n");  
                break;  
        case 2: 
				printf("Wednesday.\n");  
                break;  
        case 3: 
				printf("Thursday.\n");  
                break;  
        case 4: 
				printf("Friday.\n");  
                break;  
        case 5: 
				printf("Saturday.\n");  
                break;  
        case 6: 
				printf("Sunday.\n");  
                break;
		default:
				printf("Invalid.\n");  
				  
    }  
  
    return 0;  
} 
OUTPUT:

Enter a year :
2008

The day on 01 January 2008 was Tuesday.

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.