Program to print weekday depending upon entered day number

Logic:

  • Enter day number
  • Weekdays starts from Monday
  • If day number=1, weekday is Monday
  • If day number=2, weekday is Tuesday
  • If day number=3, weekday is Wednesday
  • If day number=4, weekday is Thursday
  • If day number=5, weekday is Friday
  • If day number=6, weekday is Saturday
  • If day number=7, weekday is Sunday
  • Otherwise, you have entered Wrong day number

Algorithm

  1. Enter day number as dno
  2. switch (dno)
  3. {
  4. case 1:
  5. printf(“monday”);
  6. break;
  7. case 2:
  8. printf(“tuesday”);
  9. break;
  10. case 3:
  11. printf(“wednesday”);
  12. break;
  13. case 4:
  14. printf(“thrusday”);
  15. break;
  16. case 5:
  17. printf(“friday”);
  18. break;
  19. case 6:
  20. printf(“saturday”);
  21. break;
  22. case 7:
  23. printf(“sunday”);
  24. break;
  25. default:
  26. printf(“wrong day”);
  27. }

Program

#include <stdio.h>
int main()
{
    printf("**********************************************************\n");
    printf("**********************************************************\n");
    printf("**      WAP to enter a day number and tell weekday      **\n");
    printf("**           Created by Sheetal Garg                    **\n");
    printf("**            Assistant Professor                       **\n");
    printf("**            Phone No:9467863365                       **\n");
    printf("**********************************************************\n");
    printf("**********************************************************\n");
    int dno; // day no.
    printf("enter day no.");
    scanf("%d", &dno);
    switch (dno)
    {
    case 1:
        printf("monday");
        break;
    case 2:
        printf("tuesday");
        break;
    case 3:
        printf("wednesday");
        break;
    case 4:
        printf("thrusday");
        break;
    case 5:
        printf("friday");
        break;
    case 6:
        printf("saturday");
        break;
    case 7:
        printf("sunday");
        break;
    default:
        printf("wrong day");
    }
    return 0;
}

Output 1:

**********************************************************
**********************************************************
**      WAP to enter a day number and tell weekday      **
**           Created by Sheetal Garg                    **
**            Assistant Professor                       **
**            Phone No:9467863365                       **
**********************************************************
**********************************************************
enter day no.
1
monday

Output 2:

**********************************************************
**********************************************************
**      WAP to enter a day number and tell weekday      **
**           Created by Sheetal Garg                    **
**            Assistant Professor                       **
**            Phone No:9467863365                       **
**********************************************************
**********************************************************
enter day no.
8
wrong day
error: You can only copy the programs code and output from this website. You are not allowed to copy anything else.