Please support our C advertiser: Programming Forums
Views: 1967 | Replies: 18
![]() |
•
•
Join Date: Mar 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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!
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!
•
•
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 11,070
Reputation:
Rep Power: 33
Solved Threads: 118
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.
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.
Dani the Computer Science Gal
•
•
Join Date: Mar 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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
please help!
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
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.
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;
} I'm here to prove you wrong.
>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).
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).
I'm here to prove you wrong.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode