Enter the number of days 1000 1000 is equivalent to 2 years, 38 weeks and 4 days
Users Online
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Latest Articles
Articles Hierarchy
C# Program to Convert Days into Years, Months and Days
C# Program to Convert Days into Years, Months and Days
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.