-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path44-CountSaturdayOfMonth.cs
39 lines (35 loc) · 1.09 KB
/
44-CountSaturdayOfMonth.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HackerRank
{
internal static class CountSaturday_Solution
{
public static int TotalSaturdayOfMonth(int year, int month)
{
int totalDay = DateTime.DaysInMonth(year, month);
int count = 0;
for (int i = 1; i <= totalDay; i++)
{
DateTime checkDate = new DateTime(year, month, i);
string day = checkDate.DayOfWeek.ToString();
if (day.ToLower() == "saturday")
count++;
}
return count;
}
}
internal class CountSaturday_Result
{
public static void Input()
{
int year = 2022;
int month = 4;
string monthName= new DateTime(year,month,1).ToString("MMMM");
int result = CountSaturday_Solution.TotalSaturdayOfMonth(year,month);
Console.WriteLine($"Total no of saturdays in {monthName } are: {result}");
}
}
}