Q:

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

belongs to collection: C# Basic Programs | basics

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to convert the US dollar into Indian ru... >>
<< C# program to change the case of entered character...