w3resource logo


C# Sharp Programming Exercises

C# Sharp Exercises: Print the name of the first three letters of month of a year starting form current date

Secondary Nav

C# Sharp DateTime : Exercise-51 with Solution

Write a program in C# Sharp to print the name of month in full starting from current date.

Expected Output :

The twelve months are : 
 September
 October  
 November December January
 February 
 March
 April  
 May     
 June     
 July     
 August

C# Sharp Code:

using System;

class dttimeex51
{
    static void Main()
    {
    Console.Write("\n\n Display the name of the months of a year :\n");
	Console.Write("-----------------------------------------------\n");
	DateTime now = DateTime.Now;
	Console.WriteLine(" The date of Today : {0}",now.ToString("dd/MM/yyyy"));
	Console.WriteLine(" The twelve months are :");
	for (int i = 0; i < 12; i++)
	{
	    Console.WriteLine(" {0}",now.ToString("MMMM"));
	    now = now.AddMonths(1);
	}
	Console.WriteLine();
    }
}

C# Sharp Practice online:

using System;

class dttimeex51
{
    static void Main()
    {
    Console.Write("\n\n Display the name of the months of a year :\n");
	Console.Write("-----------------------------------------------\n");
	DateTime now = DateTime.Now;
	Console.WriteLine(" The date of Today : {0}",now.ToString("dd/MM/yyyy"));
	Console.WriteLine(" The twelve months are :");
	for (int i = 0; i < 12; i++)
	{
	    Console.WriteLine(" {0}",now.ToString("MMMM"));
	    now = now.AddMonths(1);
	}
	Console.WriteLine();
    }
}

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program