C# Sharp Exercises: Add given number of months between zero and fifteen months to a given date
C# Sharp DateTime: Exercise-14 with Solution
Write a C# Sharp program to add specified number of months between zero and fifteen months to the last day of August, 2016.
Sample Solution:-
C# Sharp Code:
using System;
public class Example14
{
public static void Main()
{
var dat = new DateTime(2016, 8, 31);
for (int ctr = 0; ctr <= 15; ctr++)
Console.WriteLine(dat.AddMonths(ctr).ToString("d"));
}
}
Sample Output:
8/31/2016 9/30/2016 10/31/2016 11/30/2016 12/31/2016 1/31/2017 2/28/2017 3/31/2017 4/30/2017 5/31/2017 6/30/2017 7/31/2017 8/31/2017 9/30/2017 10/31/2017 11/30/2017
Flowchart:

C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write C# Sharp Program to add 30 seconds and the number of seconds in one day to a DateTime value.
Next: Write a C# Sharp program to display the date of past and future fifteen years of a specified date.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Exercises: Weekly Top 12 Most Popular Topics
- Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools
- JavaScript: HTML Form Validation
- SQL Exercises, Practice, Solution - SUBQUERIES
- C Programming Exercises, Practice, Solution : For Loop
- Python Exercises, Practice, Solution
- Python Data Type: List - Exercises, Practice, Solution
- C++ Basic: Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - exercises on Employee Database
- SQL Exercises, Practice, Solution - exercises on Movie Database
- SQL Exercises, Practice, Solution - exercises on Soccer Database
- C Programming Exercises, Practice, Solution : Recursion