//To print the multiplication table of a number upto an upper bound //@author-Karan Narain(10111017) #include int main() { // d1 and d2 for dates m1 and m2 for months y1 and y2 for years and day for storing the value of day which second date belongs and days are intermediateresult // diff is for storing the number of days between these days and result day for finding which day was date1 given date2 int d1,m1,y1,d2,m2,y2,day,resultday; long days1,days2,diff; printf("enter the dates\n "); scanf("%d %d %d %d %d %d",&d1,&m1,&y1,&d2,&m2,&y2); printf("enter the day of second date\n"); scanf("%d",&day); //intialize values days1=0; days2=0; //caluculating total number of days for the given dates with respect to 0/0/0 date and subtract those two values to get the difference // caluculating extra days in the current year leaving previous days switch(m1) { case 1: days1=d1; break; case 2: days1=31+d1; break; case 3: days1=31+28+d1; break; case 4: days1=31+28+31+d1; break; case 5: days1=31+28+31+30+d1; break; case 6: days1=31+28+31+30+31+d1; break; case 7: days1=31+28+31+30+31+30+d1; break; case 8: days1=31+28+31+30+31+30+31+d1; break; case 9: days1=31+28+31+30+31+30+31+31+d1; break; case 10:days1=31+28+31+30+31+30+31+31+30+d1; break; case 11: days1=31+28+31+30+31+30+31+31+30+31+d1; break; case 12: days1=31+28+31+30+31+30+31+31+30+31+30+d1; break; } // adding one more day if y1 is leap year and month is greater than 2 if(y1/4==0 && m1>2) days1=days1+1; // total days for date1 days1=days1+(365*y1)+(y1/4); // y1/4 is adding one extra day for every leap year starting from 0th year // do the same thing for date2 switch(m2) { case 1: days2=d2; break; case 2: days2=31+d2; break; case 3: days2=31+28+d2; break; case 4: days2=31+28+31+d2; break; case 5: days2=31+28+31+30+d2; break; case 6: days2=31+28+31+30+31+d2; break; case 7: days2=31+28+31+30+31+30+d2; break; case 8: days2=31+28+31+30+31+30+31+d2; break; case 9: days2=31+28+31+30+31+30+31+31+d2; break; case 10:days2=31+28+31+30+31+30+31+31+30+d2; break; case 11: days2=31+28+31+30+31+30+31+31+30+31+d2; break; case 12: days2=31+28+31+30+31+30+31+31+30+31+30+d2; break; } // adding one more day if y2 is leap year and month is greater than 2 if(y2/4==0 && m2>2) days2=days2+1; // total days for date1 days2=days2+(365*y2)+(y2/4); // y2/4 is adding one extra day for every leap year starting from 0th year diff=days2-days1; // making diff as positive value if(diff<0) diff= -diff; // now caluculate the day // make day between 0 to 7 for easy use of modulus and modify after resultday= (day+(diff%7))%7+1; // diff%7 is for finding how many days are completed over multiple of 7 and second modulus is for wrapping the value to 0 to 6 // and adjust it to 1 to 7 by adding 1 printf("number of days are : %d",diff); switch(resultday) { case 1: printf("sunday"); break; case 2: printf("monday"); break; case 3: printf("tuesday"); break; case 4: printf("wednesday"); break; case 5: printf("thursday"); break; case 6: printf("friday"); break; case 7: printf("saturday"); break; } }