×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

C program to read weekday number and print weekday name using switch

This program will read weekday number (0-6) and print weekday name (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday) according to given weekday number using switch case statement in c programming language.

Print weekday name program according to given weekday number using switch

/*C program to read weekday number and print 
weekday name using switch.*/

#include <stdio.h>

int main() {
  int wDay;

  printf("Enter weekday number (0-6): ");
  scanf("%d", & wDay);

  switch (wDay) {
  case 0:
    printf("Sunday");
    break;
  case 1:
    printf("Monday");
    break;
  case 2:
    printf("Tuesday");
    break;
  case 3:
    printf("Wednesday");
    break;
  case 4:
    printf("Thursday");
    break;
  case 5:
    printf("Friday");
    break;
  case 6:
    printf("Saturday");
    break;
  default:
    printf("Invalid weekday number.");
  }
  printf("\n");
  return 0;
}

Output

First Run:
Enter weekday number (0-6): 3
Wednesday

Second run:
Enter weekday number (0-6): 9
Invalid weekday number.

C Switch Case Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.