bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / letusc / luc018.c

luc018.c (1220B)


      1 /* According to Gregorian calender, it was Monday on the date 01/01/01.
      2 if any year is input through the keyboard write a program to find out
      3 what is the day on 1st January of this year. */
      4 /* Let Us C, Chap- 3, Page - 53, Qn No.: f(i) */
      5 
      6 #include <stdio.h>
      7 
      8 int is_leap(int year) {
      9     if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
     10         return 1;
     11     }
     12     return 0;
     13 }
     14 
     15 int main() {
     16     long long year; // long long for year input if years far in the future/past are tested
     17     int i;
     18     long long total_days = 0;
     19     int day_index;
     20     
     21     // Day names array for output
     22     const char *day_names[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
     23 
     24     printf("Enter the year (e.g., 2025): ");
     25     if (scanf("%lld", &year) != 1 || year < 1) {
     26         printf("Invalid year input. Please enter a positive integer year (>= 1).\n");
     27         return 1;
     28     }
     29     int years_passed = year - 1;
     30     long long leap_years = years_passed / 4 - years_passed / 100 + years_passed / 400;
     31     total_days = years_passed * 365 + leap_years;
     32     day_index = (total_days + 1) % 7;
     33     printf("\nOn January 1st, %lld, the day was: %s.\n", year, day_names[day_index]);
     34     return 0;
     35 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror