Write a program in C# Sharp to get the last day of the current year against a given date

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

Write a program in C# Sharp to get the last day of the current year against a given date. 
Test Data:
Input the Day : 12
Input the Month : 12
Input the Year : 2012
Expected Output :

The formatted Date is : 12/12/2012                                     
 The Last day of the year 2012 is : 31/12/2012 

الأجوبة

using System;

class dttimeex47
{
    static void Main()
    {
  	int dt,mn,yr;
    Console.Write("\n\n Find  the last day of a year against a date :\n");
	Console.Write("---------------------------------------------------\n");	
	Console.WriteLine(" The Last day of the current year is : {0} \n", LastDayOfYear().ToString("dd/MM/yyyy"));
    Console.Write(" Input the Day : ");
    dt = Convert.ToInt32(Console.ReadLine());	
    Console.Write(" Input the Month : ");
    mn = Convert.ToInt32(Console.ReadLine());	
    Console.Write(" Input the Year : ");
    yr = Convert.ToInt32(Console.ReadLine());		
	DateTime d = new DateTime(yr, mn, dt);
	Console.WriteLine(" The formatted Date is : {0}",d.ToString("dd/MM/yyyy"));
    DateTime nd=LastDayOfYear(d);
	Console.WriteLine(" The Last day of the year {0} is : {1}\n", yr,nd.ToString("dd/MM/yyyy"));      
    }
	
    static DateTime LastDayOfYear()
    {
	return LastDayOfYear(DateTime.Today);
    }
    static DateTime LastDayOfYear(DateTime d)
    {
	DateTime n = new DateTime(d.Year + 1, 1, 1);
	return n.AddDays(-1);
    }
}
هل كان المحتوى مفيد؟

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

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