Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to compute the exact number of days between any two dates in his

ID: 3534602 • Letter: W

Question

Write a program to compute the exact number of days between any two dates in history. Call this program file b.c. A sample run, with user input in boldface, would be:

Note that the year must be entered as four digits since it can be from any century. (For this assignment you can ignore the fact that different calendars have been used in different periods in history, and just extend the calendar we currently use forward and backward in time.) The program should check the input format for each date, including: month between 1 and 12, and date within the actual number of days for that month. If an input error occurs the program should print an appropriate message and re-input the date. Use the following rule to compute leap years:

Any year which is a multiple of 4 is a leap year;
unless it’s also a multiple of 100, in which case it’s not a leap year; unless it’s also a multiple of 400, in which case it is a leap year. For example, 1800 is not a leap year, but 1600 is a leap year.

Requirement:
 Your program shall be able to process input like following: (Multiple run)

Explanation / Answer

Please rate with 5 stars :)


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

void days(int,int,int,int,int,int);
int month(int,int);
int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};

main()
{
int a1,b1,c1,a2,b2,c2;
clrscr();
printf("Enter first date(dd mm yyyy) : ");
scanf("%d%d%d",&a1,&b1,&c1);
printf(" Enter second date(dd mm yyyy) : ");
scanf("%d%d%d",&a2,&b2,&c2);
if(c2>=c1)
days(c1,c2,b1,b2,a1,a2);
else
days(c2,c1,b2,b1,a2,a1);
getch();
}

void days(int y1,int y2,int m1,int m2,int d1,int d2)
{
int count=0,i;
for(i=y1;i<y2;i++)
{
if(i%4==0)
count+=366;
else
count+=365;
}
count-=month(m1,y1);
count-=d1;
count+=month(m2,y2);
count+=d2;
if(count<0)
count=count*-1;
printf("The no. of days b/w the 2 dates = %d days",count);
}

int month(int a,int yy)
{
int x=0,c;
for(c=0;c<a-1;c++)
{
if(c==1)
{
if(yy%4==0)
x+=29;
else
x+=28;
}
else
x+=mon[c];
}
return(x);
}


This perfectly works :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote