Question
C language question 1.input year,month -> print calender 2. input year,month, date -> print the day of the week ( if i input wrong year,
C language question
1.input year,month -> print calender
2. input year,month, date -> print the day of the week ( if i input wrong year, month, date -> print default)
#include
int is_leap_year(int year); int count_leap_year(int year); int this_year_days(int year, int month);
int main() { int year, month, date, dayofw, tot_days=0,c=0,last_year; printf("Enter the date(year month date) : "); scanf("%d %d %d", &year, &month, &date); last_year=year-1; if (last_year ==0) tot_days =0; else{ tot_days=(365 * last_year)+ count_leap_year(last_year); } tot_days += this_year_days(year, month); tot_days += date-1; dayofw = tot_days%7; switch (dayofw){ case 0: printf("%d %d %d is Monday ", year, month, date); break; case 1: printf("%d %d %d is Tuesday ", year, month, date); break; case 2: printf("%d %d %d is Wednesday ", year, month, date); break; case 3: printf("%d %d %d is Thursday ", year, month, date); break; case 4: printf("%d %d %d is Friday ", year, month, date); break; case 5: printf("%d %d %d is Saturday ", year, month, date); break; case 6: printf("%d %d %d is Sunday ", year, month, date); break; }
} int is_leap_year(int y) { if (y%4==0){ if(y%100 ==0){ if(y%400==0) return 1; return 0; } return 1; } else return 0; }
int count_leap_year(int y) { int i, cnt=0; for(i=1;i<=y;i++) { if (is_leap_year(i)) cnt++; } return cnt; }
int this_year_days(int year,int month) { int i, tot=0; for(i=1;i switch (i) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: tot += 31; break; case 4: case 6: case 9: case 11: tot+=30; break; case 2: if(is_leap_year(year)) tot+=29; else tot+=28; break; } } return (tot);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started