Skip to content
Home » Finding out the Age in Terms of Years Months and Days in C

Finding out the Age in Terms of Years Months and Days in C

Learn about Finding out the Age in Terms of Years, Months and Days in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Finding out the Age in Terms of Years, Months and Days in C

We will use five variables in this code. Totalday is a variable that stores the age in terms of days entered by the user. The year is simply computed as totalday / 365 and saved in the field “year.” We need the remaining day to determine the month and days, which is calculated as totalday % 365. Months and days are now calculated as rem/30 and rem%30, respectively.

Source code:

#include<stdio.h>
int main()
{
  int totalday, year, month, day;
  int rem;

  printf("Enter the age in days: ");
  scanf("%d",&totalday);

  year = totalday / 365;
  rem = totalday % 365;

  month = rem / 30;
  day = rem % 30;

  printf("The age is %d year %d month %d days\n", 
                year, month, day);

  return 0;
} 

Output:

Enter the age in days: 11984
The age is 32 year 10 month 4 days

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Simple C Program to Find the Total Cost of the Vehicle
Finding the Number of Conversion Characters in scanf Function in C