ok basically me and a friend are learning C language and we're totally stuck on this problem in the textbook and want to get around it before moving on.
We're totally useless so a nudge in the right direction or any help at all would be awesome.

heres the problem:

Write a program to compute and print the day of Easter Sunday in 2006. The output should be in the form:

Month m, day n.

Where m is the month number (3 for March, 4 for April), and n is the day in the month.

The date for Easter Sunday is March(22 + a + b), where

a = (19c + 24) remainder 30
b = (2d + 4e + 6a + 5) remainder 7
c = year remainder 19
d = year remainder 4
e = year remainder 7

If (22 + a + b) is greater than 31, the date is in April.
You will need to do a division and remainder to correct for this.

Make sure that your program also works for other years - including 1991, 1997 and 2018!

Recommended Answers

All 18 Replies

Member Avatar for iamthwee

Hullo,

You need to use the modulus operator to get the remainder. The rest is simple as pie. I can't envisage any other problems.

Cool thanks looking into it now in the book. =)

anything else?

remember we are complete programming retards =S

We use the / operator to signify integer division. Basically what it means is to throw away the remainder. Therefore, 6 / 3 = 2 but 7 / 3 = 2 as well.

Modular division is remainder division and its operator is the percent sign. It means to throw away the integer and only keep the remainder. Therefore, 7 % 3 = 1 and 9 % 5 = 4.

Cool thanks for helping us get on the right track =)

Any more help would be much appreciated =)

ok tried a few things and ended up with this yet still nothing.
we're very useless someone plzzzz help!

/*This program will print the day of Easter Sunday in 2006*/


#include <stdio.h>


int main () {


float a,b,c,d,e;


a = (19c + 24) remainder 30;
b = (2d + 4e + 6a + 5) remainder 7;
c = year remainder 19;
d = year remainder 4;
e = year remainder 7;


printf("a=%a b=%a",d,e);
}

that basically doesnt run and gives alot of errors :S please help!

>that basically doesnt run and gives alot of errors
That's no surprise. remainder is neither a keyword nor an operator, so the compiler looks for an identifier that you've defined. Because you haven't done so, an error is thrown. You also haven't defined year, so the same problem exists for that.

The remainder operator is %, but it doesn't work on floating-point values. For that you need to use the fmod function in <math.h>.

The way you translated the equations suggests you don't realize that C has an operator for multiplication, *. You don't simply merge the two operands to get the product; the compiler can't parse that.

Because double is the default type for floating-point, you would have an easier time avoiding the float type and going straight to double.

c, d, and e are uninitialized when you first use them. It looks like you haven't ordered your statements properly. c should be initialized before a with d and e initialized before b. Better names would do you a world of good.

The %a format modifier only exists for C99, and most compilers aren't compatible with C99. %f would suit you better at this point.

Finally, main returns an integer, so you would do well to actually make good on that by returning an integer.

#include <stdio.h>
#include <math.h>

int main ( void )
{
  double a, b, c, d, e;
  int year = 2006;

  c = fmod ( year, 19.0 );
  a = fmod ( 19 * c + 24, 30 );
  d = fmod ( year, 4.0 );
  e = fmod ( year, 7.0 );
  b = fmod ( 2 * d + 4 * e + 6 * a + 5, 7 );

  printf ( "a = %.2f\nb = %.2f\n", d, e );

  return 0;
}

hmmm ok thanks.

We're trying to get our minds around your program, but when we ran it, it didnt actually do what the problem asks of it to do.

Where do we need to go from here?

>Where do we need to go from here?
Understand the calculations that you're asked to perform and adjust the code accordingly. I fixed legitimate errors and only guestimated on the logic. If you want help with the logic, you'll need to be more specific about the problem (ie. what input you'll give, what output you're getting, what output you expect, and a breakdown of how the formulae work for our less mathematically inclined helpers).

Perhaps a little nudge in a slightly different direction.

Specify the problem in sudo code - and don't worry about actual code yet.
This applies to any computer program in any language.

Remember, in C and C++, you must declare a variable before using it. ( Well actually you can do both at the same time. eg: int x = 25; )

Take note of the order in which variables are computed. For example, you cannot compute 'a' without first computing 'c'

SUDO-CODE
// Input the year 
=> code here
// c = year remainder 19.
=> code here
// d = year remainder 4
=> code here
// e = year remainder 7
=> code here
// a = (19c + 24) remainder 30
=> code here
// b = (2d + 4e + 6a + 5) remainder 7
=> code here
// The date for Easter Sunday is March(22 + a + b)
=> code here

>Specify the problem in sudo code - and don't worry about actual code yet.
It's "pseudo code", and that's what he had at first.

>> It's "pseudo code"
Thanks for the spelling correction.
>> that's what he had at first.
I don't agree with that statement. Pseudo code, by my definition, should give a verbal flow of the proposed program, and can be left in place, as comment lines, when the code is added.
The initial post did not do that. It was just a problem definition.

>I don't agree with that statement.
That's your prerogative, though your definition of pseudocode would be nothing more than unnecessary fluff on top of the pseudocode statements already provided.

Perhaps a constructive discussion... :)

Based on your statement of 'Yesterday, 9:06AM'
>> If you want help with the logic, you'll need to be more specific about the problem (ie. what input you'll give, what output you're getting, what output you expect, and a breakdown of how the formulae work for our less mathematically inclined helpers)
It is clear that even you do not believe the problem has been clearly stated.
The purpose of the pseudo code is to clearly define the problem in simple, easy to understand text (no code).... including the logic flow.

>> That's your prerogative, though your definition of pseudocode would be nothing more than unnecessary fluff on top of the pseudocode statements already provided.
In this particular case, I somewhat agree with you. But the original poster's 'provided' code does NOT handle the program flow.

>> We're totally useless so a nudge in the right direction or any help at all would be awesome.
Based on this statement, it is clear that the OP is very new to programming. So perhaps the 'unnecessary fluff' could be of benefit.

Believe what you want to, but it sounds a lot like you're asking for complete code from someone who's having trouble coming up with any code at all. That's a lot like saying "You want to know where the bug is? Well, fix it first and then we'll help you find it".

>> ... but it sounds a lot like you're asking for complete code from someone who's having trouble coming up with any code at all.
Perhaps I am not being clear...
There is NO CODE in pseudo code. It's just a text outline of the proposed program

>There is NO CODE in pseudo code.
Your definition isn't the official definition. Please don't talk in absolutes when you're stating an opinion.

lol thanks to everyone for the help =)

we managed to not only make the program work but with all the help made it so you can input the year you want and get the date for that year. =D

Thanks again, can't wait for the help next time =)

u guys are awesome keep it up =)

here is the final program we got:

/* This is a program that will print out the day and month for Easter Sunday */

#include <stdio.h>

int main () {
    int year;
    int a, b, c, d, e, n, m;

    printf("Enter year: ");
    scanf("%d", &year);

    c = year % 19;
    d = year % 4;
    e = year % 7;

    a = (19 * c + 24) % 30;
    b = (2*d + 4*e + 6*a + 5) % 7;

    m = 3;
    n = 22 + a + b;

    if (n > 31) {
        n -= 31;
        ++m;
}

    printf("Month %d, day %d.\n", m, n);

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.