Find the first day of a given year from a base year having first day as Monday | C ++ Implementation of the above approach ; Function to find the day of 1 st January of Y year ; Count years between years Y and B ; Count leap years ; Non leap years ; Total number of days in the years lying between the years Y and B ; Actual day ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findDay ( int Y , int B ) { int lyear , rest , totaldays , day ; Y = ( Y - 1 ) - B ; lyear = Y / 4 ; rest = Y - lyear ; totaldays = ( rest * 365 ) + ( lyear * 366 ) + 1 ; day = ( totaldays % 7 ) ; if ( day == 0 ) printf ( " Monday " ) ; else if ( day == 1 ) printf ( " Tuesday " ) ; else if ( day == 2 ) printf ( " Wednesday " ) ; else if ( day == 3 ) printf ( " Thursday " ) ; else if ( day == 4 ) printf ( " Friday " ) ; else if ( day == 5 ) printf ( " Saturday " ) ; else if ( day == 6 ) printf ( " Sunday " ) ; else printf ( " INPUT ▁ YEAR ▁ IS ▁ WRONG ! " ) ; } int main ( ) { int Y = 2020 , B = 1900 ; findDay ( Y , B ) ; return 0 ; }