This is a C# Program to convert a given number of days in terms of years, weeks & days.

This C# Program Converts a Given Number of Days in terms of Years, Weeks & Days.

Here this program accepts the number of days. Given the number of days, then it calculates the years, weeks & days for this number.

Here is source code of the C# Program to Convert a Given Number of Days in terms of Years, Weeks & Days. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/* * C# Program to Convert a Given Number of Days in terms of * Years, Weeks & Days */ using System; class program { public static void Main() { int ndays, year, week, days, DAYSINWEEK=7; Console.WriteLine("Enter the number of days"); ndays = int.Parse(Console.ReadLine()); year = ndays / 365; week = (ndays % 365) / DAYSINWEEK; days = (ndays % 365) % DAYSINWEEK; Console.WriteLine("{0} is equivalent to {1}years, {2}weeks and {3}days", ndays, year, week, days); Console.ReadLine(); } }

In this C program, we are reading the number of days using ‘ndays’ integer variable. Convert the given number of days to a measure of time given in years, weeks and days. For example 375 days is equal to 1 year, 1 week, and 3 days (ignore leap year).

The year variable is used to calculate the number of years from the value of ‘ndays’ variable. Divide the value of ‘ndays’ variable by 365. Compute the modulus of the value of ‘ndays’ variable by 365 and divide the resulted value by the value of ‘daysinweek’. Compute the number of days using the modulus of the value of ‘ndays’ variable by 365. Print the number of days in terms of years, weeks and days.

Enter the number of days 1000 1000 is equivalent to 2 years, 38 weeks and 4 days

**Sanfoundry Global Education & Learning Series – 1000 C# Programs.**

**Next Steps:**

- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

**Related Posts:**

- Apply for C# Internship
- Buy MCA Books
- Buy Computer Science Books
- Practice Computer Science MCQs
- Buy C# Books