C # Calculates the day ordinal of a year

Source: Internet
Author: User


int y, d, M;
int m1 = to, M2 = 31, M3 = To, M4 =, M5 = To, M6 =, M7 = to, M8 = to, M9 =, M10 =, M11 =--M12
Console.WriteLine ("Please enter the Year");
y = Convert.ToInt32 (Console.ReadLine ());
If (y% 400 = = 0 | | (y% 4 = = 0 && y% 100! = 0))
{
m2 = 29;
}
Console.WriteLine ("Please enter the month (input not will be treated as default 1)");
m = Convert.ToInt32 (Console.ReadLine ());
if (M > | | m < 1)
{
m = 1;
}

Console.WriteLine ("Please enter a date (the input will not be treated as default 1)");
D = Convert.ToInt32 (Console.ReadLine ());

Switch (m)
{
Case 1:

if (D > M1 | | d < 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + d.tostring () + "Day");
Break
Case 2:

if (d> m2 | | d < 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + (M1 + D). ToString () + "Day");
Break
Case 3:

if (d > M3 | | d < 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + (M1 + m2 + d). ToString () + "Day");
Break
Case 4:

if (d > M4 | | d < 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + (M1 + m2 + m3 + d). ToString () + "Day");
Break

Case 5:

if (d > M5 | | d < 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + (M1 + m2 + m3 + m4 + D). ToString () + "Day");
Break
Case 6:

if (d > M6 | | d< 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + (M1 + m2 + m3 + M4 + M5 + D). ToString () + "Day");
Break
Case 7:

if (d > M7 | | d < 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + (M1 + m2 + m3 + M4 + M5 + M6 + D). ToString () + "Day");
Break
Case 8:

if (d > M8 | | d < 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + D). ToString () + "Day");
Break
Case 9:

if (d> M9 | | D < 1)
{
D= 1;
}
Console.WriteLine (Y + "year" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + D). ToString () + "Day");
Break
Case 10:

if (d > M10 | | d < 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + D). ToString () + "Day");
Break
Case 11:

if (d > M11 | | d < 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + M10 + D). ToString () + "Day");
Break
Case 12:

if (d > M12 | | d < 1)
{
D = 1;
}
Console.WriteLine (Y + "year" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + M10 + M11 + D). ToString () + "Day");
Break

Default
Console.WriteLine ("You entered the wrong");
Break
}

Console.ReadLine ();

C # Calculates the day ordinal of a year

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.