Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Read month number and display month name


C# Sharp Conditional Statement: Exercise-22 with Solution

Write a program in C# Sharp to read any Month Number in integer and display Month name in the word.

Sample Solution:-

C# Sharp Code:

using System;  
public class Exercise22  
{  
    public static void Main()
{
   int monno;


           Console.Write("\n\n");
           Console.Write("Read month number and display month name:\n");
           Console.Write("-------------------------------------------");
           Console.Write("\n\n");


         Console.Write("Input Month No : ");
         monno = Convert.ToInt32(Console.ReadLine());

   switch(monno)
   {
	case 1:
	       Console.Write("January\n");
	       break;
	case 2:
	       Console.Write("February\n");
	       break;
	case 3:
	       Console.Write("March\n");
	       break;
	case 4:
	       Console.Write("April\n");
	       break;
	case 5:
	       Console.Write("May\n");
	       break;
	case 6:
	       Console.Write("June\n");
	       break;
	case 7:
	       Console.Write("July\n");
	       break;
	case 8:
	       Console.Write("August\n");
	       break;
	case 9:
	       Console.Write("September\n");
	       break;
	case 10:
	       Console.Write("October\n");
	       break;
	case 11:
	       Console.Write("November\n");
	       break;
	case 12:
	       Console.Write("December\n");
	       break;
	default:
	       Console.Write("invalid Month number. \nPlease try again ....\n");
	       break;
      }
   }
}

Sample Output:

Read month number and display month name:                                                                     
-------------------------------------------                                                                   
Input Month No : 2                                                                                            
February

Pictorial Presentation:

Conditional Statement: Read month number and display month name.

Flowchart:

Flowchart: Read month number and display month name.

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to read any digit, display in the word.
Next: Write a program in C# Sharp to read any Month Number in integer and display the number of days for this month.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.