C Program to Display Day From Given Date of User on Command Line

In this article, You are going to execute the task of “C Program to Display Day From Given Date of User on Command Line”. Yes, We can see the possibilities to perform this task below.

C Program to Display Day From Given Date of User on Command Line

C Program to Display Day From Given Date of User on Command Line

Source Code

#include<stdio.h>
 int c_Code(int c_year)
   {
       if(c_year%4==0&&c_year%100!=0||c_year%400==0)
        return 0;
       else if(c_year==1700||c_year==2100||c_year==2500||c_year==2900)
         return 5;
       else if(c_year==1800||c_year==2200||c_year==2600||c_year==3000)
        return 3;
       else if(c_year==1900||c_year==2300||c_year==2700||c_year==3100)
        return 1;
       else 
     return 0;
 }
  int main()
   {
       char dayPrint[8][15]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
       int i,cy,cc,yc,yl,day,days=0,month,year,dayCode;
       printf("Enter day, month, year : ");
       scanf("%d%d%d",&day,&month,&year);
       int monthCode[]={31,year%4==0&&year%100!=0||year%400==0?29:28,31,30,31,30,31,31,30,31,30,31};
       yc=(year-1)%100;
       cy=(year-1)-yc;
       yl=yc/4;
       cc=c_Code(cy);
       for(i=0;i<month-1;i++){
          days+=monthCode[i];
       }
       days=days+day;
       dayCode=(cc+yc%7+yl%7+days%7)%7;
       printf("Day : %s",dayPrint[dayCode]);
       return 0;
   }

Final Words

I hope this article “C Program to Display Day From Given Date of User on Command Line” will be beneficial to you. If you need any help regarding this article then let us know via the comment section. We are ready to help you. Share this article with other C/C++ developers to help them.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment