This program gives the exact age of the person with automatic comparing the present date and Person DOB.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int bd, bm,by,ans1,ans2,ans3;
int i,j,k;
int m[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
time_t t = time(NULL);
struct tm tm = *localtime(&t);
printf("Today's date is: %d-%d-%d \n", tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
printf("Enter the DOB: ");
scanf("%d-%d-%d",&bd, &bm, &by);
i = tm.tm_mday;
j = tm.tm_mon + 1;
k = tm.tm_year + 1900;
if (bd > i)
{
i = i + (m[bm - 1]);
j = (j - 1);
}
if (bm > j)
{
k = (k - 1);
j = (j + 12);
}
ans1 = i - bd;
ans2 = j - bm;
ans3 = k - by;
printf("Your present age is: %d year %d months %d days",ans3,ans2,ans1);
return 0;
}