Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions

Question

=+what kinds of policies and practices should be developed?

Answered: 1 week ago