is this programm efficient to find the day of the given date . can it be more normalized ?

is this programm efficient to find the day of the given date . can it be more normalized ?

#include <stdio.h>

int main(void)
{
    int dd,mm,yy,i,leap=0,ordi=0,odd_years,month_days= 0,total ;
    char week[7][10] ;
strcpy(week[0], "Sunday") ;
strcpy(week[1], "Monday") ;
strcpy(week[2], "Tuesday") ;
strcpy(week[3], "Wednesday") ;
strcpy(week[4], "Thursday") ;
strcpy(week[5], "Friday") ;
strcpy(week[6], "Saturday") ;
    int month[12]={31,28,31,30,31,30,31,30,31,30,31,30};
    scanf("%d %d %d",&dd,&mm,&yy);
    for(i=yy-1;i>1;i--)
    {
        if(i%4==0)
        {
            leap+=2;
        }
        else

        ordi++;

        }

    printf("%d %d\n",leap , ordi);
    odd_years = leap+ordi;
    odd_years = odd_years % 7;
    printf("%d\n",odd_years);
    for(i=0;i<mm-1;i++)
    {
        month_days = month_days+ month[i];
    }
    if(yy%4==0)
    {
    month_days++;
    month_days = month_days % 7;


    }
    if(yy%4 !=0)
    {
        month_days = month_days % 7;
    }




    printf("%d\n",month_days);
    dd= dd % 7;
    printf("%d\n",dd);
    total = odd_years+month_days+dd;
    total = total %7;
    printf("%d\n",total);
    printf("the day is %s",week[total]);

    // your code goes here
    return 0;
}
View Answers









Related Tutorials/Questions & Answers:

Ads