w3resource
C# Sharp Programming Exercises

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

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?



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