write a program to display the name of month of the year using switch case
Answers
Answer:
/* C Program to display month name according to the month number using Switch Statement */
#include<stdio.h>
int main()
{
int n;
printf("Month No : ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("January");
break;
case 2:
printf("February");
break;
case 3:
printf("March");
break;
case 4:
printf("April");
break;
case 5:
printf("May");
break;
case 6:
printf("June");
break;
case 7:
printf("July");
break;
case 8:
printf("August");
break;
case 9:
printf("September");
break;
case 10:
printf("October");
break;
case 11:
printf("November");
break;
case 12:
printf("December");
break;
default:
printf("Invalid Month number\nPlease try again ....\n");
break;
}
return 0;
}
Explanation:
HOPE IT IS HELPFUL.
import java.util.*;
class Hello
{
public static void main (string args [])
{
Scanner sc=new Scanner(System .in);
int d;
System.out.println("Enter a month no.");
d=sc.nextInt();
switch=(d)
{
Case1: System.out.println("January");
break;
Case2: System.out.println("February");
break;
Case3: System.out.println("March");
break;
Case4: System.out.println("April");
break;
Case5: System.out.println("May");
break;
Case6: System.out.println("June");
break;
Case7: System.out.println("July");
break;
Case8: System.out.println("August");
break;
Case9: System.out.println("September");
break;
Case10: System.out.println("October");
break;
Case11: System.out.println("November");
break;
Case12: System.out.println("December");
break;
default: System.out.println("Wrong Month");
}
}
}