#include #include #include #include //#include "date.h" int day_of_week(int day, int month, int year); int FindSunday(int z, int year); void SetupScreen(); void main() { int year, a, b, c, d, e, f, x, y, z, type, sun; SetupScreen(); Start: do{ clrscr(); gotoxy(10, 5); printf("Press 1 for Orthodox Easter, 2 for Western Easter, 0 to exit: "); scanf("%d", &type); }while( type != 1 && type != 2 && type != 0 ); if( type == 1 ) { gotoxy(10, 8); printf("Enter the year: "); scanf("%d", &year); a = year % 19; x = a * 11; y = x % 30; z = 40 - y; if( z > 30 ) z -= 30; sun = FindSunday( z, year); gotoxy( 15, 10); switch( sun ) { case 1: printf("Easter is on Baramuda %d, which is April 9.", z); break; case 2: printf("Easter is on Baramuda %d, which is April 10.", z); break; case 3: printf("Easter is on Baramuda %d, which is April 11.", z); break; case 4: printf("Easter is on Baramuda %d, which is April 12.", z); break; case 5: printf("Easter is on Baramuda %d, which is April 13.", z); break; case 6: printf("Easter is on Baramuda %d, which is April 14.", z); break; case 7: printf("Easter is on Baramuda %d, which is April 15.", z); break; case 8: printf("Easter is on Baramuda %d, which is April 16.", z); break; case 9: printf("Easter is on Baramuda %d, which is April 17.", z); break; case 10: printf("Easter is on Baramuda %d, which is April 18.", z); break; case 11: printf("Easter is on Baramuda %d, which is April 19.", z); break; case 12: printf("Easter is on Baramuda %d, which is April 20.", z); break; case 13: printf("Easter is on Baramuda %d, which is April 21.", z); break; case 14: printf("Easter is on Baramuda %d, which is April 22.", z); break; case 15: printf("Easter is on Baramuda %d, which is April 23.", z); break; case 16: printf("Easter is on Baramuda %d, which is April 24.", z); break; case 17: printf("Easter is on Baramuda %d, which is April 25.", z); break; case 18: printf("Easter is on Baramuda %d, which is April 26.", z); break; case 19: printf("Easter is on Baramuda %d, which is April 27.", z); break; case 20: printf("Easter is on Baramuda %d, which is April 28.", z); break; case 21: printf("Easter is on Baramuda %d, which is April 29.", z); break; case 22: printf("Easter is on Baramuda %d, which is April 30.", z); break; case 23: printf("Easter is on Baramuda %d, which is May 1.", z); break; case 24: printf("Easter is on Baramuda %d, which is May 2.", z); break; case 25: printf("Easter is on Baramhat %d, which is April 3.", z); break; case 26: printf("Easter is on Baramhat %d, which is April 4.", z); break; case 27: printf("Easter is on Baramhat %d, which is April 5.", z); break; case 28: printf("Easter is on Baramhat %d, which is April 6.", z); break; case 29: printf("Easter is on Baramhat %d, which is April 7.", z); break; case 30: printf("Easter is on Baramhat %d, which is April 8.", z); break; } getch(); goto Start; } else if( type == 2) { gotoxy(10, 8); printf("Enter the year: "); scanf("%d", &year); a = year % 19; b = year % 4; c = year % 7; y = 19 * a + 24; d = y % 30; z = 2*b + 4*c + 6*d + 5; e = z % 7; f = d + e; if( f < 34 ) { x = f + 22; } else if( f == 34 ) { if( d != 28 ) x = f + 22; else x = f + 15; } else { x = f + 15; } gotoxy( 15, 10); if( x > 31 ) { printf("Easter is on April %d.", x-31); } else { printf("Easter is on March %d.", x); } getch(); goto Start; } else { window(1, 1, 80, 25); textattr(0x0F); clrscr(); } } /* Copyright (C) 1993 Marc Stern (internet: stern@mble.philips.be) */ /*** * * Function : day_of_week * * Return : 0 = sunday, 1 = monday,... * * Decisions : If date is not valid, return -1. * ***/ int day_of_week( int day, int month, int year ) { struct tm dtime; // if ( ! isdatevalid(day , month , year) ) // return -1; dtime.tm_year = year - 1900; dtime.tm_mon = month - 1; dtime.tm_mday = day; dtime.tm_hour = 0; dtime.tm_min = 0; dtime.tm_sec = 1; dtime.tm_isdst = -1; /* call mktime to fill in the weekday field of the structure */ if( mktime( &dtime ) == -1 ) return -1; return dtime.tm_wday; /* const signed char calendar[12] = { 0, 1, -1, 0, 0, 1, 1, 2, 3, 3, 4, 4 } return ( 365L *(year - 1) + (year - 1)/4 - (year - 1)/100 - (year - 1)/400 + (month - 1) * 30 + calendar[month - 1] + isleapyear(year) && (month > 2) + day ) % 7; */ /* const signed char calendar[12] = { 6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 } int century; long result = 0; if ( isleapyear(year) && (month < 3) ) result = -1; century = year / 100; year %= 100; result += (century*5 + century/4 + year + year/4 + day + calendar[month])% 7; We can precompute x = (century * 5 + century / 4 + year + year / 4) % 7 and use result += ( x + day + calendar[month] ) % 7 */ } int FindSunday(int z, int y) { int dow, day, mon; if( z <= 22) { mon = 4; day = z + 8; } else if( z <= 24 ) { mon = 5; day = z - 22; } else { mon = 4; day = z - 22; } dow = day_of_week(day, mon, y); z += (7 - dow); return z; } /******************** * * Function to setup the screen colors and the border around the screen. * ********************/ void SetupScreen() { int i; /* * Set up screen mode */ textmode(C80); /* Define screen mode to 80x25 */ textattr(0x1F); /* Yellow foreground on Blue background */ clrscr(); /* * Draw a border for better looks */ /* Start with the upper left corner */ putch(0xC9); /* Now the whole top line */ for( i=1; i < 79; i++) putch(0xCD); /* Now the upper right border */ putch(0xBB); /* Now the vertical edges */ for( i=2; i < 25; i++) { gotoxy(1,i); putch(0xBA); gotoxy(80,i); putch(0xBA); } /* Now the lower left corner */ putch(0xC8); /* Now the bottom line */ for( i=1; i < 79; i++) putch(0xCD); /* Finally the lower right corner */ _wscroll = 0; /* Turn wrapping off */ putch(0xBC); _wscroll = 1; /* Turn it back on */ /* Create the working window */ window(2,2,79,24); /* Window that we will actually use */ textattr(0x1E); /* Yellow foreground on Blue background */ }