Monday, 25 December 2017

Finding the day using the given date

     

  Hello,here you can find the program which gives what will be the day of the date you asked.
         This program works on the principle of odd days.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int day,month,year,odd=0,m[12]={3,0,3,2,3,2,3,3,2,3,2,3},i,rem=-1,ch;
clrscr();
scanf("%d %d %d",&day,&month,&year);
if(day<=31 && day>0 && month>0 && month<=12 &&year>0)
{
odd=odd+day;
for(i=0;i<month-1;i++)
odd+=m[i];
       rem=year%400;

       if(rem<=200 && rem>0){
       for(i=1;i<rem;i++)
       {
if((i%4)==0)
{
odd+=2;
}
else
{
odd+=1;
}
       }
       }
       else if(rem>200)
       {
rem=400-rem;
for(i=rem;i>1;i--)
{
if((i%4)==0) odd+=2;
else
odd+=1;
}
       }
       if(rem==0) odd--;
       ch=odd%7;
       switch(ch)
       {
case 0:printf("SUNDAY");
break;
case 1:printf("MONDAY");
break;
case 2:printf("TUESDAY");
break;
case 3:printf("WEDNESDAY");
break;
case 4:printf("THURSDAY");
break;
case 5:printf("FRIDAY");
break;
case 6:printf("SATURDAY");
break;
       }
    }
    else
printf("Error in the date you have mentioned\n");
}

Output:





If you want to know the principle of odd days comment below,i am sured that i will explain.

    Thank you and keep supporting me.

No comments:

Post a Comment