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#?
Submitted by Nidhi, on September 14, 2020

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

Program:

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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.