Write C# Program to enter month number and print number of days in month

Write C# Program to enter month number and print number of days in month


Introduction

Write C# Program to enter month number and print number of days in month. 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. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class csharpExercise
  7. {
  8. static void Main(string[] args)
  9. {
  10. int month;
  11.  
  12. Console.WriteLine("Enter month number (1-12): ");
  13. month = Convert.ToInt32(Console.ReadLine());
  14.  
  15. if (month == 1)
  16. {
  17. Console.WriteLine("Enter month : January \nNo. of days : 31 days");
  18. }
  19. else if (month == 2)
  20. {
  21. Console.WriteLine("Enter month : February \nNo. of days : 28 or 29 days");
  22. }
  23. else if (month == 3)
  24. {
  25. Console.WriteLine("Enter month : March \nNo. of days : 31 days");
  26. }
  27. else if (month == 4)
  28. {
  29. Console.WriteLine("Enter month : April \nNo. of days : 30 days");
  30. }
  31. else if (month == 5)
  32. {
  33. Console.WriteLine("Enter month : May \nNo. of days : 31 days");
  34. }
  35. else if (month == 6)
  36. {
  37. Console.WriteLine("Enter month : June \nNo. of days : 30 days");
  38. }
  39. else if (month == 7)
  40. {
  41. Console.WriteLine("Enter month : July \nNo. of days : 31 days");
  42. }
  43. else if (month == 8)
  44. {
  45. Console.WriteLine("Enter month : August \nNo. of days : 31 days");
  46. }
  47. else if (month == 9)
  48. {
  49. Console.WriteLine("Enter month : September \nNo. of days : 30 days");
  50. }
  51. else if (month == 10)
  52. {
  53. Console.WriteLine("Enter month : October \nNo. of days : 31 days");
  54. }
  55. else if (month == 11)
  56. {
  57. Console.WriteLine("Enter month : November \nNo. of days : 30 days");
  58. }
  59. else if (month == 12)
  60. {
  61. Console.WriteLine("Enter month : December \nNo. of days : 31 days"); ;
  62. }
  63. else
  64. {
  65. Console.WriteLine("Invalid input! Please enter month number between (1-12).");
  66. }
  67. Console.ReadLine();
  68. }
  69. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts