-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathAge_in_Days_Months_Year.c
28 lines (28 loc) · 1.01 KB
/
Age_in_Days_Months_Year.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#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("Present Age Years: %d Months: %d Days: %d", final_year, final_month, final_date);
}
int main() {
int present_date = 21;
int present_month = 9;
int present_year = 2019;
int birth_date = 25;
int birth_month = 9;
int birth_year = 1996;
age(present_date, present_month, present_year, birth_date, birth_month, birth_year);
return 0;
}