Question

Please write a C program to implement the calendar of the year (after the year 1900)...

Please write a C program to implement the calendar of the year (after the year 1900) you specify. For example, when you input 1900, the program print the calendar of year 1900 as the figure (partial) down below. Hint 1: Jan. 1st, 1900 is Monday. Hint 2: You will need to consider the case of Leap Year where there are 29 days in the month of February. In common years there are 28 days in the month of February. For the determination of Leap Year, you are referred to https://en.wikipedia.org/wiki/Leap_year.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

int num[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *month[]=
{
   " ",
   "\n\n\nJanuary",
   "\n\n\nFebruary",
   "\n\n\nMarch",
   "\n\n\nApril",
   "\n\n\nMay",
   "\n\n\nJune",
   "\n\n\nJuly",
   "\n\n\nAugust",
   "\n\n\nSeptember",
   "\n\n\nOctober",
   "\n\n\nNovember",
   "\n\n\nDecember"
};

int getCode(int year)
{
   int code;
   int d1, d2, d3;
  
   d1 = (year - 1.)/ 4.0;
   d2 = (year - 1.)/ 100.;
   d3 = (year - 1.)/ 400.;
   code = (year + d1 - d2 + d3) %7;
   return code;
}


int leapYear(int year)
{
   if(year% 4 == 0 && year%100 != 0 || year%400 == 0)
   {
       num[2] = 29;
       return 1;
   }
   else
   {
       num[2] = 28;
       return 0;
   }
}

void dispCalender(int year, int code)
{
   int i, day;
   for ( i = 1; i <= 12; i++ )
   {
       printf("%s", month[i]);
       printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" );

       for ( day = 1; day <= 1 + code * 5; day++ )
       {
           printf(" ");
       }

       for ( day = 1; day <= num[i]; day++ )
       {
           printf("%2d", day );

           if ( ( day + code ) % 7 > 0 )
               printf("   " );
           else
               printf("\n " );
       }
           code = ( code + num[i] ) % 7;
   }
}

int main(void)
{
   int year, code, leapyear;
   printf("Please enter a year after 1900 : ");
   scanf("%d", &year);
   code = getCode(year);
   leapYear(year);
   dispCalender(year, code);
   printf("\n");
}


main.c Please enter a year after 1900 : 2019 January Sun Mon 6 13 20 27 7 14 21 28 Tue Wed Thu Fri Sat 1 2 3 4 8 9 10 11 12 1

Add a comment
Know the answer?
Add Answer to:
Please write a C program to implement the calendar of the year (after the year 1900)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:      ...

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:             0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...

  • Use Java please Creating a calendar for a given year A shell for this assignment has...

    Use Java please Creating a calendar for a given year A shell for this assignment has been provided so that you can fill in the methods Homework 4 grading rubric 1. Output examples a. One Normal Year, 10% b. One Leap Year, 10% 2. Style Meaningful variable names, 10% b. Meaningful method names, 10 % c. Comments, Total: 10% . Do not comment every line. 5% . Comment non-obvious code. 5% a d. Indentation, 10% e. Block comment with name...

  •    Lab/HW 3   Write a program that reads in the following data, all entered on one...

       Lab/HW 3   Write a program that reads in the following data, all entered on one line with at least one space separating them: a) an integer representing a month b) an integer representing the day of the month c) an integer representing a year 1. Check that the month is between 1 and 12. If it’s not print an error message. 2. Day cannot be 0 or less nor can it be more than 31 for all months. Print...

  • c++ please :) First, ask the user to enter a year (4-digit) and what week day...

    c++ please :) First, ask the user to enter a year (4-digit) and what week day does this year starts with (String) For example, the year 2018 starts with the week day "Friday". In this case, the calendar should start from January 1 which is Friday, 2018 Your program should produce a formatted calendar for the specified year and there should be a blank line after each month. Moreover, the month and the year should be centered over each month....

  • PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program tha...

    PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program that reads a values for hour and minute from the input test file timeData.txt . The data read for valid hour and valid minute entries. Assume you are working with a 24 hour time format. Your program should use functions called validateHour and validateMinutes. Below is a sample of the format to use for your output file  timeValidation.txt :   ...

  • In Java You are to write a program that determines the day of the week for...

    In Java You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program: /** Interface for Date objects to be used by the Year3000 driver program. @author Jon Sorenson */ public interface DateInterface { /** @return the day of the month (1-31) */ public int getDay(); /** @return the day of...

  • Implement an Enum in Java which enumerates the months of the year. Include in the enum...

    Implement an Enum in Java which enumerates the months of the year. Include in the enum the relevant position of the month in the calender i.e. Jan = 1, Feb = 2, etc and the number of days in the month i.e. Jan = 31, Feb = 28, etc. You do not need to provide support for leap years in the implementation. Provide a suitable toString() method to print information about the enumerated types.

  • In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists...

    In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4...

  • please follow format of example output, do in python A year in the modern Gregorian Calendar...

    please follow format of example output, do in python A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT