Write a C# Sharp program to display the number of days of the year between two specified years

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program to display the number of days of the year between two specified years. 

Expected Output :

12/31/2001: day 365 of 2001                                                      
12/31/2002: day 365 of 2002                                                      
12/31/2003: day 365 of 2003                                                      
12/31/2004: day 366 of 2004 (Leap Year)                                          
12/31/2005: day 365 of 2005                                                      
12/31/2006: day 365 of 2006                                                      
12/31/2007: day 365 of 2007                                                      
12/31/2008: day 366 of 2008 (Leap Year)  
....... 

الأجوبة

using System;
public class Example4
{
   public static void Main()
   {
      DateTime dec31 = new DateTime(2000, 12, 31);
      for (int ctr = 0; ctr <= 20; ctr++) {
         DateTime dateToDisplay = dec31.AddYears(ctr);
         Console.WriteLine("{0:d}: day {1} of {2} {3}", dateToDisplay, 
                           dateToDisplay.DayOfYear,
                           dateToDisplay.Year,   
                           DateTime.IsLeapYear(dateToDisplay.Year) ? 
                                               "(Leap Year)" : ""); 
      }  
   }
} 
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...