C# program to convert entered days into years, weeks, and days

Here, we are going to learn how to convert entered days into years, weeks, and days in C#? By Nidhi Last updated : April 15, 2023

Days into Years, Weeks, and Days Conversion

Here we will read the number of days from keyword and then convert it into years, weeks, and days.

C# code for days into years, weeks, and days conversion

The source code to change the case of entered character is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to convert entered days into years, weeks, and days.

using System;

class Sample
{
    static void Main(string[] args)
    {
        int num     =0;
        int years   =0;
        int weeks   =0;
        int days    =0;
        
        
        Console.Write("Enter number of days: ");
        num = Convert.ToInt32(Console.ReadLine());
        
        years = num / 365;
        weeks = (num % 365) / 7;
        days  = (num % 365) % 7;

        Console.WriteLine("Years : " + years);
        Console.WriteLine("Weeks : " + weeks);
        Console.WriteLine("Days  : " + days );
    }
}

Output

Enter number of days: 768
Years : 2
Weeks : 5
Days  : 3
Press any key to continue . . .

Explanation

In the above program, we created a class Sample that contains the Main() method. In the Main() method, we read the number of days from the keyboard.

years = num / 365;
weeks = (num % 365) / 7;
days  = (num % 365) % 7;

In the above code we converted entered number of days into years, weeks, and days and then print the result on the console screen.

C# Basic Programs »


Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.