w3resource
C# Sharp Programming Exercises

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

C# Sharp DateTime: Exercise-50 with Solution

Write a program in C# Sharp to print the name of the first three letters of month of a year starting form current date.

Sample Solution:-

C# Sharp Code:

using System;

class dttimeex50
{
    static void Main()
    {
    Console.Write("\n\n Display the name of the first three letters of month 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("MMM"));
	    now = now.AddMonths(1);
	}
	Console.WriteLine();
    }
}

Sample Output:

Display the name of the first three letters of month of a year :                                             
---------------------------------------------------------------------                                         
 The date of Today : 12/06/2017                                                                               
 The twelve months are :                                                                                      
 Jun                                                                                                      
 Jul                                                                                                      
 Aug                                                                                                      
 Sep                                                                                                      
 Oct                                                                                                      
 Nov                                                                                                      
 Dec                                                                                                      
 Jan                                                                                                      
 Feb                                                                                                      
 Mar                                                                                                      
 Apr                                                                                                      
 May
 

Flowchart:

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

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a program in C# Sharp to get the day and month name of current date.
Next: Write a program in C# Sharp to print the name of month in full starting from current date.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming