luc018.c (1356B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* According to Gregorian calender, it was Monday on the date 01/01/01. 8 if any year is input through the keyboard write a program to find out 9 what is the day on 1st January of this year. */ 10 /* Let Us C, Chap- 3, Page - 53, Qn No.: f(i) */ 11 12 #include <stdio.h> 13 14 int is_leap(int year) { 15 if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) { 16 return 1; 17 } 18 return 0; 19 } 20 21 int main() { 22 long long year; // long long for year input if years far in the future/past are tested 23 int i; 24 long long total_days = 0; 25 int day_index; 26 27 // Day names array for output 28 const char *day_names[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 29 30 printf("Enter the year (e.g., 2025): "); 31 if (scanf("%lld", &year) != 1 || year < 1) { 32 printf("Invalid year input. Please enter a positive integer year (>= 1).\n"); 33 return 1; 34 } 35 int years_passed = year - 1; 36 long long leap_years = years_passed / 4 - years_passed / 100 + years_passed / 400; 37 total_days = years_passed * 365 + leap_years; 38 day_index = (total_days + 1) % 7; 39 printf("\nOn January 1st, %lld, the day was: %s.\n", year, day_names[day_index]); 40 return 0; 41 }