Program to calculate the number of odd days in given number of years | C ++ implementation of the approach ; Function to return the count of odd days ; Count of years divisible by 100 and 400 ; Every 4 th year is a leap year ; Every 100 th year is divisible by 4 but is not a leap year ; Every 400 th year is divisible by 100 but is a leap year ; Total number of extra days ; modulo ( 7 ) for final answer ; Driver code ; Number of days
#include <iostream> NEW_LINE using namespace std ; int oddDays ( int N ) { int hund1 = N / 100 ; int hund4 = N / 400 ; int leap = N >> 2 ; int ord = N - leap ; if ( hund1 ) { ord += hund1 ; leap -= hund1 ; } if ( hund4 ) { ord -= hund4 ; leap += hund4 ; } int days = ord + leap * 2 ; int odd = days % 7 ; return odd ; } int main ( ) { int N = 100 ; cout << oddDays ( N ) ; return 0 ; }