Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Date-Calendar is this programm efficient to find the day of the given date . can it be more normalized ?

Have Programming Question? Ask it here!
 
 
 


rajesh kumar jain
is this programm efficient to find the day of the given date . can it be more normalized ?
0 Answer(s)      9 months ago
Posted in : Date-Calendar


#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;
}

Advertisement
View Answers

Related Tutorials/Questions & Answers:
 

 

 

DMCA.com