Write C# program to print number of days in a month using switch case


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2.  
  3. public class csharpExercise
  4. {
  5. static void Main(string[] args)
  6. {
  7.  
  8. int monthnumber;
  9.  
  10. //Reading a month number from user
  11.  
  12. Console.WriteLine("Enter month number(1-12): ");
  13. monthnumber = Convert.ToInt32(Console.ReadLine());
  14.  
  15. switch (monthnumber)
  16. {
  17. case 1: Console.WriteLine("31 days");
  18. break;
  19. case 2: Console.WriteLine("28 or 29 days");
  20. break;
  21. case 3: Console.WriteLine("31 days");
  22. break;
  23. case 4: Console.WriteLine("30 days");
  24. break;
  25. case 5: Console.WriteLine("31 days");
  26. break;
  27. case 6: Console.WriteLine("30 days");
  28. break;
  29. case 7: Console.WriteLine("31 days");
  30. break;
  31. case 8: Console.WriteLine("31 days");
  32. break;
  33. case 9: Console.WriteLine("30 days");
  34. break;
  35. case 10: Console.WriteLine("31 days");
  36. break;
  37. case 11: Console.WriteLine("30 days");
  38. break;
  39. case 12: Console.WriteLine("31 days");
  40. break;
  41. default:
  42. Console.WriteLine("Invalid input!!! enter month number between 1-12");
  43. break;
  44.  
  45.  
  46. }
  47. Console.ReadLine();
  48.  
  49. }
  50. }

Result

C# language techstudy

     





Related Topics




Popular Posts