Friday, October 30, 2009

Chap10[D]g Use structure to check dates

Write a program that compares two given dates. To store date use structure say date that contains three members namely date, month and year. If the dates are equal then display message as "Equal" otherwise "Unequal".


void main()
{
int i,f=0;

struct date
{
int date;
int month;
int year;
};

struct date d[2];

for(i=0;i<2;i++)
{
printf("\nEnter day for the %d) date\n",i+1);
scanf("%d",&d[i].date);
printf("\nEnter the month for the %d) date\n",i+1);
scanf("%d",&d[i].month);
printf("\nEnter the year for the %d) date\n",i+1);
scanf("%d",&d[i].year);
}

if(d[0].date==d[1].date)
{
if(d[0].month==d[1].month)
{
if(d[0].year==d[1].year)
{
f=1;
}
}
}

if(f==1)
printf("\nThe dates are equal");

else
printf("\nThe dates are not equal");
}

No comments:

Post a Comment