#include <stdio.h>
#include <stdlib.h>
// function to calculate current age
void age(int present_date, int present_month, int present_year, int birth_date, int birth_month, int birth_year) {
int month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (birth_date > present_date) {
present_date = present_date + month[birth_month - 1];
present_month = present_month - 1;
}
if (birth_month > present_month) {
present_year = present_year - 1;
present_month = present_month + 12;
}
int final_date = present_date - birth_date;
int final_month = present_month - birth_month;
int final_year = present_year - birth_year;
printf("\nYour Present Age Is : %d Years %d Months %d Days", final_year, final_month, final_date);
}
int main() {
int present_date;
printf("Present Date : ");
scanf("%d",&present_date);
int present_month;
printf("Present Month : ");
scanf("%d",&present_month);
int present_year;
printf("Present Year : ");
scanf("%d",&present_year);
int birth_date ;
printf("\nBirth Date : ");
scanf("%d",&birth_date);
int birth_month;
printf("Birth Month : ");
scanf("%d",&birth_month);
int birth_year ;
printf("Birth Year : ");
scanf("%d",&birth_year);
age(present_date, present_month, present_year, birth_date, birth_month, birth_year);
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter