• Language

    C

  • Description

    Age calculation

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
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    int age, birth_day, birth_month, birth_year, current_day;
    int current_month, current_year;
    printf ("Enter the value of birth day: ");
    scanf ("%d", &birth_day);
    (void) getchar ();
    printf ("Enter the value of birth month: ");
    scanf ("%d", &birth_month);
    (void) getchar ();
    printf ("Enter the value of birth year: ");
    scanf ("%d", &birth_year);
    (void) getchar ();
    printf ("Enter the value of current day: ");
    scanf ("%d", &current_day);
    (void) getchar ();
    printf ("Enter the value of current month: ");
    scanf ("%d", &current_month);
    (void) getchar ();
    printf ("Enter the value of current year: ");
    scanf ("%d", &current_year);
    (void) getchar ();
    age=current_year-birth_year;
    if(birth_month>current_month||(birth_month==current_month&&birth_day>current_day))
        age=age-1;
    printf ("Value of age: %d\n", age);
    putchar ('\n');
    system ("pause");
    return EXIT_SUCCESS;
}