Calculate your age program in C

Calculate your age program in C Programming is an interesting problem to solve.

Do you want to know anybody’s age just by entering the “year of birth” of that person?

Check out the code after giving it a try by yourself.

Calculate your age program in C

#include<stdio.h>
int main()
{
    int current_year,b,d;
    printf("Enter Year of Birth\n");
    scanf("%d",&b);
    printf("Enter Current year\n");
    scanf("%d",&current_year);
    if(current_year==0)
    {
        d=100-b;
    }
    else if(current_year>b)
    {
        d=current_year-b;
    }
    else
    {
        d=(100+current_year)-b;
    }
    printf("Your age is %d",d);
    return 0;
}

Leave a Reply