Write C# program to print day of week name 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 weeknumber;
  9.  
  10. //Reading week no from user
  11. Console.WriteLine("Enter week number(1-7): ");
  12. weeknumber = Convert.ToInt32(Console.ReadLine());
  13.  
  14. switch (weeknumber)
  15. {
  16. case 1: Console.WriteLine("Monday");
  17. break;
  18. case 2: Console.WriteLine("Tuesday");
  19. break;
  20. case 3: Console.WriteLine("Wednesday");
  21. break;
  22. case 4: Console.WriteLine("Thursday");
  23. break;
  24. case 5: Console.WriteLine("Friday");
  25. break;
  26. case 6: Console.WriteLine("Saturday");
  27. break;
  28. case 7: Console.WriteLine("Sunday");
  29. break;
  30. default:
  31. Console.WriteLine("Invalid input! Please enter week no. between 1-7.");
  32. break;
  33.  
  34. }
  35. Console.ReadLine();
  36.  
  37. }
  38. }

Result

C# language techstudy

     





Related Topics




Popular Posts