Friday, 19 April 2019

Program to print day on the date given as input.

#include<stdio.h>
#include<conio.h>

struct date{
    int day,mon,year;
}dat;

int main(){
    int y,f,o_day,od_temp,i,temp,c,o_year,l_year;

    while(1){
        y=0,o_day=0,od_temp=0;temp=0;
        printf("Enter Date (dd/mm/yyyy): ");
        scanf("%d/%d/%d",&dat.day,&dat.mon,&dat.year);

        f=dat.year%4==0 ? 29:28;
        int d[12]={31,f,31,30,31,30,31,31,30,31,30,31};

        while(temp<=dat.year)
            temp+=400;
        if(temp>dat.year)
            temp-=400;
        dat.year-=temp;

        c=(dat.year-dat.year%100)/100;
        od_temp=5*c+c/4;
        od_temp%=7;

        y=dat.year%100-1;
        l_year=y/4;
        o_year=y-l_year;
        od_temp+=(2*l_year+o_year);
        od_temp%=7;

        temp=0;
        for(i=0;i<dat.mon-1;i++)
            temp+=d[i];
        temp+=dat.day;

        od_temp+=temp%7;
        o_day=od_temp%7;

        switch(o_day){
        case 1:
            printf("Monday");
            break;
        case 2:
            printf("Tuesday");
            break;
        case 3:
            printf("Wednesday");
            break;
        case 4:
            printf("Thusday");
            break;
        case 5:
            printf("Friday");
            break;
        case 6:
            printf("Saturday");
            break;
        case 0:
            printf("Sunday");
            break;
        }
        printf("\n\n");
    }
}

No comments:

Post a Comment

Popular Posts