In this post, we will write a C++ program to find out the day from the given date starting from Jan 2001.

C++ program to find out the day of given date starting from Jan. 2001


C++ program to find out the day of the given date starting from Jan 2001.

#include<iostream>
#include<conio.h>

int main(void)
{
system("cls");

    int d,m,y;
    int n = 0;
    int ly = 0;
    int td,r,i,j,ny;

    std::cout<<"Enter the day dd(01) = ";
    std::cin>>d;
    std::cout<<"Enter the month mm(01) = ";
    std::cin>>m;
    std::cout<<"Enter the year yy from (2001) = ";
    std::cin>>y;

    for(i=1;i<m;i++)
    {
        if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12)
            n = n+31;
        else if (i==2 && y%4 !=0)
            n = n+28;
        else if (i==2 && y%4 == 0)
            n = n+29;
        else if (i==4 || i==6 || i==9 || i==11)
            n = n + 30;
    }
    for(j = 2001;j<y;j++)
    {
        if(j%4 == 0)
            ly = ly+1;
    }

    ny=(y-2000)-1;
    td = ly+n+d+(ny*365);
    r = td%7;

    switch(r)
    {
        case 0:
            std::cout<<"The day is Sunday";
            break;
        case 1:
            std::cout<<"The day is Monday";
            break;
        case 2:
            std::cout<<"The day is Tuesday";
            break;
        case 3:
            std::cout<<"The day is Wednesday";
            break;
        case 4:
            std::cout<<"The day is Thursday";
        case 5:
            std::cout<<"The day is Friday";
            break;
        case 6:
            std::cout<<"The day is Saturday";
            break;
    }

    getch();
    return 0;
}



Output

Enter the day dd(01) = 23
Enter the month mm(01) = 3
Enter the year yy from (2001) = 2022
The day is Wednesday