Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a problem about C programming Thanks a lot ! Write a program that accepts

ID: 3622818 • Letter: I

Question

I have a problem about C programming
Thanks a lot !
Write a program that accepts three integer values presented as the arguments to
this program which correspond to a day, month and year. If other than three are
supplied the program is to produce an error message and terminate, otherwise the
program is to continue as specified below.
The day of the week is then to be calculated using Zeller's congruence, the
technique is detailed below.
Assume that "year", "month" and "day" have been given as three integers, for
example 1965, 8, 23 respectively for August 23rd 1965. The calculation continues.
if month < 3 then
month=month+12
year=year-1
end if
Then
nd = ((13*month+3)+day+year+year-year@+year) mod 7
The result, nd, gives the day: 0 is Monday 1 is Tuesday etc.
Notes:
? The sign is used to indicate integer division (ignore the remainder) – to
achieve the desired result simply use integers for everything.
? The "mod 7" terms means find the remainder after dividing by 7. Note: in C
Mod is calculated using the ‘%’ , ie 16%7 is 16 mod 7 = 2
Hint: use sscanf to read the values from the string values passed as arguments to
the programme

Thanks agagin !

Explanation / Answer

I don't check if it is a leap year (Fed has 29 days if it is a leap year)

Sourcecode

#include <stdio.h>
#include <stdlib.h> //for system() function

int main()
{
    int n,iDay;
    const char DAY[7][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
    int month, day, year;
    const int daysPerMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31 };

    printf("Enter (Day Month Year):");
    scanf("%d %d %d",&day,&month,&year);

     //check if it is a valid date (not leap year)
    if(year>0 && month>=1 && month <=12 && day>0 && day<=daysPerMonth[month-1])
    {
        n = 1461*(month<=2 ? year-1 : year)/4
        + 153*(month<=2 ? month+13 : month+1)/5
        + day;

        iDay = (n-621049)%7;
   
        printf("%i/%i/%i is %s ",month,day,year,DAY[iDay]);   
    }
    else
        printf("This is not a valid date! ");
   
   
    system("pause");
    return 0;
}

Or you can download via this link : http://www.mediafire.com/?ycdad262cmj2jj0