#include<stdio.h>
struct dt
{
int dd;
int mm;
int yy;
}dob,c_date,today,c_date_1;
int main()
{
printf("Enter Date of birth in dd/mm/yyyy format: ");
scanf("%d/%d/%d",&dob.dd,&dob.mm,&dob.yy);
printf("Enter Current date in dd/mm/yyyy format : ");
scanf("%d/%d/%d",&c_date.dd,&c_date.mm,&c_date.yy);
c_date_1 = c_date;
if(c_date.yy<dob.yy)
{
printf("Current Date Should not less than Date of Birth\n");
}
else
{
/* Diff of two date */
if(c_date.dd>=dob.dd)
today.dd = c_date.dd-dob.dd;
else
{
c_date.dd+=30;
c_date.mm-=1;
today.dd = c_date.dd-dob.dd;
}
if(c_date.mm>=dob.mm)
today.mm = c_date.mm-dob.mm;
else
{
c_date.mm+=12;
c_date.yy-=1;
today.mm = c_date.mm-dob.mm;
}
today.yy = c_date.yy-dob.yy;
printf("Current date is : ");
printf("%02d/%02d/%04d\n",c_date_1.dd,c_date_1.mm,c_date_1.yy);
printf("Date of Birth : ");
printf("%02d/%02d/%04d\n",dob.dd,dob.mm,dob.yy);
printf("Your age is %d years %d Months %d Days \n",today.yy,today.mm,today.dd);
if(today.yy>=18)
printf("Congrats!-you are eligible to Vote:\n");
else
printf("Sorry! -you are not eligible to Vote:\n");
}
return 0;
}
struct dt
{
int dd;
int mm;
int yy;
}dob,c_date,today,c_date_1;
int main()
{
printf("Enter Date of birth in dd/mm/yyyy format: ");
scanf("%d/%d/%d",&dob.dd,&dob.mm,&dob.yy);
printf("Enter Current date in dd/mm/yyyy format : ");
scanf("%d/%d/%d",&c_date.dd,&c_date.mm,&c_date.yy);
c_date_1 = c_date;
if(c_date.yy<dob.yy)
{
printf("Current Date Should not less than Date of Birth\n");
}
else
{
/* Diff of two date */
if(c_date.dd>=dob.dd)
today.dd = c_date.dd-dob.dd;
else
{
c_date.dd+=30;
c_date.mm-=1;
today.dd = c_date.dd-dob.dd;
}
if(c_date.mm>=dob.mm)
today.mm = c_date.mm-dob.mm;
else
{
c_date.mm+=12;
c_date.yy-=1;
today.mm = c_date.mm-dob.mm;
}
today.yy = c_date.yy-dob.yy;
printf("Current date is : ");
printf("%02d/%02d/%04d\n",c_date_1.dd,c_date_1.mm,c_date_1.yy);
printf("Date of Birth : ");
printf("%02d/%02d/%04d\n",dob.dd,dob.mm,dob.yy);
printf("Your age is %d years %d Months %d Days \n",today.yy,today.mm,today.dd);
if(today.yy>=18)
printf("Congrats!-you are eligible to Vote:\n");
else
printf("Sorry! -you are not eligible to Vote:\n");
}
return 0;
}