Write a function that counts how many months have passed fro
Write a function that counts how many months have passed from a given date, passed in to the function. The date only includes the month and the year. Date: 2 2016 Months passed: 12 static int GetNumberOfMonthsPassed (int month, int year)
Solution
Function:
static int GetNumberOfMonthsPassed(int month,int year){
DateTime now = DateTime.Now;
int current_month = now.Month;
int current_year = now.Year;
int diff_year = current_year - year;
int diff_month = current_month - month;
int num = Math.Abs(diff_month+12*(diff_year));
Console.WriteLine(\"Months Passed:\"+num);
}
Sample Input & Output of Function:
Date: 5 2016 /*month:5 year:2016*/
Months Passed: 9
