Write a program in C# Sharp to find the last day of a month against a given date
- برمجة سي شارب
- برمجة
- 2021-06-01
- ahmadghneem
الأجوبة
using System;
class dttimeex55
{
static void Main()
{
int yr,mn,dt;
Console.Write("\n\n Find the last day of the month against a given date :\n");
Console.Write("----------------------------------------------------------\n");
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"));
Console.WriteLine(" The last day of the month for the above date is : {0}\n", LastDayOfMonth(d).ToString("dd/MM/yyyy"));
}
public static DateTime LastDayOfMonth(DateTime dt)
{
DateTime ss= new DateTime(dt.Year, dt.Month, 1);
return ss.AddMonths(1).AddDays(-1);
}
}أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال