Question

Programming in C, need help implementing this function. This function gets the number of days in...

Programming in C, need help implementing this function. This function gets the number of days in the given month

int getFirstDayOfMonth(int mon, int year) {

// Use Zeller's algorithm here. Pseudo code for Zeller’s algorithm:

declare adjusted month, set to (mon + 9) % 12 + 1

declare adjusted year, set to year - 2000


if adjusted month is greater than 10:

subtract one from adjusted year


declare day, set to 1

declare century, set to 20

declare output, set to

(13 * adjusted mon - 1) / 5 + adjusted year / 4 + century / 4 + day +

adjusted year - 2 * century;

mod output by 7

add 7 to output

mod output by 7 again

return output

}

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

I have written the program using C PROGRAMMING LANGUAGE.

INPUT:

I have given the Input date as 24/09/2019 (DD/MM/YYYY)

OUTPUT :

CODE :

//included the stdio library

#include <stdio.h>

//function definition for getFirstDayOfMonth

int getFirstDayOfMonth(int mon, int year) {

//Zeller's algorithm

int Adjustedmonth,Adjustedyear,day,century,output;

//declare adjusted month, set to (mon + 9) % 12 + 1

Adjustedmonth = (mon + 9) % 12 + 1;

//declare adjusted year, set to year - 2000

Adjustedyear = year - 2000;

/*if adjusted month is greater than 10:

subtract one from adjusted year*/

if(Adjustedmonth > 10){

Adjustedyear = Adjustedyear - 1;

}

//declare day, set to 1

day = 24;

//declare century, set to 20

century = 20;

/*declare output, set to (13 * adjusted mon - 1) / 5 + adjusted year / 4 + century / 4 + day + adjusted year - 2 * century;*/

output = (13 * Adjustedmonth - 1) / 5 + Adjustedyear / 4 + century / 4 + day + Adjustedyear - 2 * century;

// mod output by 7

output = output%7;

//add 7 to output

output = output + 7;

//mod output by 7 again

output = (output+1)%7;

return output; //returned the output

}

//main method

int main(void) {

int result ;//declared the result integer variable

//Calling the getFirstDayOfMonth function

result = getFirstDayOfMonth(9,2019);

printf("\nOUTPUT : \n");//print statement

//Switch Case

switch (result)

{

case 0 : printf("Saturday \n"); break;

case 1 : printf("Sunday \n"); break;

case 2 : printf("Monday \n"); break;

case 3 : printf("Tuesday \n"); break;

case 4 : printf("Wednesday \n"); break;

case 5 : printf("Thursday \n"); break;

case 6 : printf("Friday \n"); break;

}

return 0;//returned 0

}

Thanks..

Add a comment
Know the answer?
Add Answer to:
Programming in C, need help implementing this function. This function gets the number of days in...
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
  • int getFirstDayOfMonth(int mon, int year) {    int adjusted_month = (mon + 9) % 12 +...

    int getFirstDayOfMonth(int mon, int year) {    int adjusted_month = (mon + 9) % 12 + 1;       int adjusted_year = year - 2000;    if(adjusted_month > 10)        adjusted_year--;    // declare day, set to 1    int day = 1;    // declare century, set to 20    int century = 20;    // declare output, set to       // (13 * mon - 1) / 5 + year / 4 + century / 4...

  • Need help implementing this Java class (Science: day of the week) Zeller's congruence is an algorithm...

    Need help implementing this Java class (Science: day of the week) Zeller's congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h = (q + (26 * (m + 1)) / 10 + k + k / 4 + j / 4 + 5 * j) % 7 where h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). q...

  • please rewrite or convert this C program into Assembly language and please make a notice of...

    please rewrite or convert this C program into Assembly language and please make a notice of which function is which! #include <stdio.h> #include <stdlib.h> void printMonthYear(int mon,int year); void printDaysOfWeek(); void printDays(int mon,int year); int getFirstDayOfMonth(int mon, int year); int getNumOfDaysInMonth(int mon, int year); int main(void) {    int mon=-1; int year= -1; printf("Month : "); fflush(stdout); scanf("%d",&mon);    if(mon < 1|| mon > 12){ printf("Invalid month >.<!: %d ! Must be between 1 and 12\n",mon); return 1; } printf("Year...

  • I need help with a project, I’ve seen many answers in C++, but i need it to be in swift, thank you!

    I need help with a project, I’ve seen many answers in C++, but i need it to be in swift, thank you! Write a program that asks the user to enter a date (e.g. July 4, 2008) and will return the day of the week that corresponds to that date. Your program should take the input in numeric form, thus the input prompt should be as follows: Please enter a date below: Enter month (1-12): Enter day (1-31) Enter year...

  • Zeller's congruence is an algorithm developed to calculate the day of the week. Write a program...

    Zeller's congruence is an algorithm developed to calculate the day of the week. Write a program that prompts the user to enter a year, month, day of month and it displays the name of the week. Here is my source code. I need it broke down into a flowchart. public static void main(String[] args) {        //all variables are initialized to 0, because local variables require at least an initial value before use        Scanner input = new...

  • General Requirements: • You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; • You sho...

    General Requirements: • You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; • You should create identifiers with sensible names; • You should make comments to describe your code segments where they are necessary for readers to understand what your code intends to achieve. • Logical structures and statements are properly used for specific purposes. Objectives This assignment requires you to write...

  • PYTHON I need some basic python homework help! Write a program that prompts the user to...

    PYTHON I need some basic python homework help! Write a program that prompts the user to enter a date (day, month, and year). Your program will print out the day of the week for that date. You do not need to validate the input. That means you can assume: the year will be entered as a four-digit number in the range 1900 through 2100 inclusive. the month will be one of the strings "January", "February", . . ., "December". the...

  • Use c++ programming environment to implement and test a function with the following prototype: //the parameter...

    Use c++ programming environment to implement and test a function with the following prototype: //the parameter month and day should represent a valid date //return true if the date is between 3/8 and 10/31; false otherwise bool is_daylight(int month, int day); Following TDD (test-driven development), it is important to know the expected return values for different function calls. Function call Expected return Function call Expected return is_daylight(2, 20) false is_daylight(3, 7) false is_daylight(4, 1) true is_daylight(10, 31) true is_daylight(11, 1)...

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you....

    Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you. Phase 1 You must design 3 algorithms, and provide both a flow chart and pseudo code for the algorithms.    Algorithm descriptions: Given an integer parameter named current_number and two constant global variables: const int MIN_NUMBER = 1; const int MAX_NUMBER = 8; Create an algorithm named forward, that will advance ONE value through a sequence of numbers 1, 2, 3 ... MAX_NUMBER. In...

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