Question

In: Computer Science

Use Zeller’s algorithm to figure out the days of the week for a given date in...

Use Zeller’s algorithm to figure out the days of the week for a given date in c.

W = (d + 13(m+1)/5 + y + y/4 + c/4 - 2c + 6) mod 7

Y is the year minus 1 for January or February, and the year for any other month

y is the last 2 digits of Y

c is the first 2 digits of Y

d is the day of the month (1 to 31)

m is the shifted month (March=3,...January = 13, February=14)

w is the day of week (0=Sunday,..,6=Saturday)

Output should look the following:

Please enter the day [YYYY/Month/Day]: 2020/1/1

Wednesday

Solutions

Expert Solution

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..


Related Solutions

USE PYTHON to find out What day of the week is a given date? i.e. On...
USE PYTHON to find out What day of the week is a given date? i.e. On what day of the week was 5 August 1967? if it is given that 1 January 1900 was a tuesday Write a function is_leap() which takes 1 input argument, an integer representing a year, and returns True if the year was a leap year, and False if it was not. .Then, write a function days_since() which takes 3 input integers day, month, year, representing...
You have to use the numbers that is given to figure out what the question is...
You have to use the numbers that is given to figure out what the question is asking. 1. You are the Nutrition and Food Services Director and your Chief Financial Officer (CFO) has requested that you evaluate the inventory within the department. Specifically, the CFO wishes to know if the facility is effectively managing the inventory.    To accomplish this task, you will evaluate the inventory turnover from the previous quarter. You have determined the following information: Inventory value at the...
What day of the week is a given date? i.e. On what day of the week...
What day of the week is a given date? i.e. On what day of the week was 5 August 1967? if it is given that 1 January 1900 was a tuesday Write a function is leap() which takes 1 input argument, an integer representing a year, and returns True if the year was a leap year, and False if it was not. .Then, write a function days_since() which takes 3 input integers day, month, year, representing a date (after 1st...
1. If you are given an equipotential diagram, how could you use it to figure out...
1. If you are given an equipotential diagram, how could you use it to figure out the direction of the electric field at a specific location? Explain your thinking in detail, using both words and a picture. 2. If you are given an equipotential diagram, how could you use it to figure out which regions have a stronger electric field and which regions have a weaker electric field? Explain your thinking in detail, using both words and a picture.
Create a swap method without a temporary variable. Implement an algorithm to figure out if someone...
Create a swap method without a temporary variable. Implement an algorithm to figure out if someone has won a game of tic-tac-toe. import java.util.Arrays; public class ArrayReview { private int data[]; public ArrayReview(int n) { data = new int[n]; for (int i = 0; i < n; i++) { data[i] = (int) (Math.random() * 100); } } public int[] getData() { return data; } public void setData(int[] data) { this.data = data; } @Override public String toString() { return Arrays.toString(data);...
This is a radix sort algorithm. please add the date type and the instruction given inside...
This is a radix sort algorithm. please add the date type and the instruction given inside the code to make it completely work. please do not change the code just follow the instruction. #include <iostream> using namespace std; // Returns the length, in number of digits, of value int RadixGetLength(int value) { if (value == 0) return 1; int digits = 0; while (value != 0) { digits = digits + 1; value = value / 10; } return digits;...
Is it possible to figure out, WITHOUT THE USE OF GRAPH, if the sample of a...
Is it possible to figure out, WITHOUT THE USE OF GRAPH, if the sample of a data comes from Normal Distribution? If it is possible that by doing some kind of mathematical calculation we can find if a distribution is normal or not? If you could share some example(s), that would be great.
From the information given below, compute the time in days for the following notes: Date of...
From the information given below, compute the time in days for the following notes: Date of Note Due Date Time in Days 1. June 28, 2010 August 10, 2010 days 2. March 5, 2010 August 12, 2010 days 3. April 20, 2010 July 17, 2010 days 4. January 12, 2010 May 15, 2010 days 5. December 17, 2010 February 2, 2011 days From the information given below, determine the due date for the following notes:        Date of Note       Time...
The anwsers that was given is not correct. I have tried but cant figure it out>...
The anwsers that was given is not correct. I have tried but cant figure it out> out You are evaluating a project for The Ultimate recreational tennis racket, guaranteed to correct that wimpy backhand. You estimate the sales price of The Ultimate to be $440 per unit and sales volume to be 1,000 units in year 1; 1,250 units in year 2; and 1,325 units in year 3. The project has a 3-year life. Variable costs amount to $245 per...
Consider the following work breakdown structure: Given a due date of 210 days, what is the...
Consider the following work breakdown structure: Given a due date of 210 days, what is the earliest you can start activity D without delaying the project? Time Estimates (days) Activity Precedes Optimistic Most Likely Pessimistic Start A,B - - - A C,D 44 50 56 B D 45 60 75 C E 42 45 48 D F 31 40 49 E F 27 36 39 F End 58 70 82 50 60 70 100 140
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT