Pages

Friday, 12 October 2012

Write a program in C# that accepts a number between 1 and 7 from the user and returns the corresponding day of a week. (1 - Monday, 2 -Tuesday and so on)

Write a program in C# that accepts a number between 1 and 7 from the user and returns the corresponding day of a week. (1 - Monday, 2 -Tuesday and so on)

Description:
In this post we are going to learn switch case .
Open Microsoft visual studio
File-> New -> Project -> visual c#-> console Application

Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace dayoftheweek
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter No. of Week:");
            int i = Convert.ToInt16(Console.ReadLine());
    switch(i)
                {
                    case 1:Console.WriteLine("\t Monday");
                            break;
                   case 2:Console.WriteLine("\t Tuesday");
                            break;
                   case 3: Console.WriteLine("\t Wednesday");
                            break;
                case 4:   Console.WriteLine("\t Thursday");
                        break;
                case 5: Console.WriteLine("\t Friday");
    break;
              case 6: Console.WriteLine("\t Saturday");
                       break;
                case 7: Console.WriteLine("\t Sunday");
                        break;
                }
             
            Console.ReadLine();

        }
    }
}

Demo:
Write a program in C# that accepts a number between 1 and 7 from the user and returns the corresponding day of a week. (1 - Monday, 2 -Tuesday and so on)
Write a program in C# that accepts a number between 1 and 7 from the user and returns the corresponding day of a week. (1 - Monday, 2 -Tuesday and so on)

Write a program in C# that accepts a number between 1 and 7 from the user and returns the corresponding day of a week. (1 - Monday, 2 -Tuesday and so on)
Write a program in C# that accepts a number between 1 and 7 from the user and returns the corresponding day of a week. (1 - Monday, 2 -Tuesday and so on)







No comments:

Post a Comment