Write a C program to input number of days from user and convert it to years, weeks and days. How to convert days into years, weeks in C programming.

Input days: 373

Output = 1 year/s, 1 week/s and 1 day/s

1 week = 7 days

Happy coding ;)

**Example:**Input days: 373

Output = 1 year/s, 1 week/s and 1 day/s

### Required knowledge

Fundamentals of C, Data types, Talking user input in C#### Conversion table

1 year = 365 days (Ignoring leap year)1 week = 7 days

### Program

/** * C program to convert days in to years, weeks and days */ #include <stdio.h> int main() { int days, years, weeks; // Read total number of days from user printf("Enter days: "); scanf("%d", &days); // Converts days to years, weeks and days years = days/365; //Ignoring leap year weeks = (days%365)/7; days = days- ((years*365) + (weeks*7)); printf("YEARS: %d\n", years); printf("WEEKS: %d\n", weeks); printf("DAYS: %d", days); return 0; }

Output

Enter days: 373

YEARS: 1

WEEKS: 1

DAYS: 1

YEARS: 1

WEEKS: 1

DAYS: 1

Happy coding ;)

### You may also like

- Basic programming exercises index.
- C program to convert length from centimeter to meter and kilometer.
- C program to convert temperature from Celsius to Fahrenheit.
- C program to convert temperature from Fahrenheit to Celsius.
- C program to calculate power of two numbers x
^{y}. - C program to find area of rectangle.
- C program to find diameter, circumference and area of circle.
- C program to calculate Simple Interest.
- C program to calculate Compound Interest.
- C program to enter week number and print day of week.
- C program to find total number of days in a month.
- C program to print different star(*) patterns.

Thanks for nice post.know details

ReplyDeletewhile finding the number of weeks, why did you use day%365? could you please explain?

ReplyDeleteHello Bloom, actually days%365 returns the remaining number of days subtracting total number of days in years found.

DeleteThis is also equivalent to weeks = (days - (years * 365)) / 7;

Lets take an example suppose days = 401

Years = 401/365 = 1

Weeks = (401 % 365)/7 = (36)/7 = 5

Days = 401 - ( (1 * 365) + (5 * 7)) = 401 - (365+35) = 1

Thank you!

DeleteI was trying to solve some problems and I can't do it (I'm a beginner by the way).

I was hoping you could help me out. Will it be a problem?

Surely, I will try my best Bloom to help you.

DeleteShould I post my problems here? Or will you give me an email address to send my problems to?

DeleteYes of-course you can post your problems here.

DeleteMake a simple program that reads four integer numbers named A, B, C, D. Calculate and print the max pair sum from all possible pair.

DeleteIn other word find the max value from (A + B), (A + C), (A + D), (B + C), (B + D) and (C + D).

Write a computer program that read time, and split the time to hour(s) and minute(s).

Delete[Don't forget about singular and plural form of hour and minute]

Example

10:30

10 Hours 30 Minutes

01:01

1 Hour 1 Minute

01:30

1 Hour 30 Minutes

Hey, Bloom for the first program this link will help you C program to find largest and second largest number.

DeleteIn real maximum pair sum is the pair of LARGEST and SECOND-LARGEST number in a given set of numbers.