Friday, March 20, 2009

CALCULATE DAYS BETWEEN TWO DATES

#include
#include
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int d[2],m[2],y[2];
long int tot[2]={0,0},di=0;
void cal(int);
void main()
{
int i;
clrscr();
for(i=0;i<2;i++)
{
printf("Enter the DATE %d: \n",i+1);
printf("\nEnter the MONTH--> ");
scanf("%d",&m[i]);
printf("\nEnter the DATE --> ");
scanf("%d",&d[i]);
printf("\nEnter the YEAR --> ");
scanf("%d",&y[i]);
cal(i);
}
di=tot[1]-tot[0]-1;
printf("\nTHE DIFFERENCE BETWEEN TO DATES--->%d",di);
getch();
}
void cal(int n)
{
int i;
tot[n]+=(y[n]-1)*365.25;
for(i=0;i<=m[n]-2;i++)
{
if(y[n]%4==0)
tot[n]+=29;
else
tot[n]+=month[i];
}
tot[n]=tot[n]+d[n];
}

No comments:

Post a Comment