Program to print name of month depending upon entered month number

Logic:

  • Enter month number
  • Month name starts from January
  • If month number=1, month is January
  • If month number=2, month is February and so on
  • If month number=12, month is December
  • Otherwise, you have entered Wrong month number

Algorithm

  1. Enter month number as mno
  2. switch (mno)
  3. {
  4. case 1:
  5. printf(“january”);
  6. break;
  7. case 2:
  8. printf(“feburary”);
  9. break;
  10. case 3:
  11. printf(“march”);
  12. break;
  13. case 4:
  14. printf(“aprail”);
  15. break; case 5:
  16. printf(“may”);
  17. break;
  18. case 6:
  19. printf(“june”);
  20. break;
  21. case 7:
  22. printf(“july”);
  23. break;
  24. case 8:
  25. printf(“august”);
  26. break;
  27. case 9:
  28. printf(“september”);
  29. break;
  30. case 10:
  31. printf(“october”);
  32. break;
  33. case 11:
  34. printf(“november”);
  35. break;
  36. case 12:
  37. printf(“december”);
  38. break;
  39. default:
  40. printf(“wrong month”);
  41. }

Program

#include <stdio.h>
int main()
{
    printf("*********************************************************");
    printf("\n*********************************************************");
    printf("\n**  WAP to enter a month number and tell month name    **");
    printf("\n**                   Created by Sheetal Garg           **");
    printf("\n**                   Assistant Professor               **");
    printf("\n**                   Phone No:9467863365               **");
    printf("\n*********************************************************");
    printf("\n*********************************************************\n");
    int mno; // month no.
    printf("enter month no.");
    scanf("%d", &mno);
    switch (mno)
    {
    case 1:
        printf("january");
        break;
    case 2:
        printf("feburary");
        break;
    case 3:
        printf("march");
        break;
    case 4:
        printf("aprail");
        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("wrong month");
    }
    return 0;
}

Output 1:

********************************************************
********************************************************
**  WAP to enter a month number and tell month name   **
**                  Created by Sheetal Garg           **
**                  Assistant Professor               **
**                  Phone No:9467863365               **
********************************************************
********************************************************
enter month no.
1
january

Output 2:

********************************************************
********************************************************
**  WAP to enter a month number and tell month name   **
**                  Created by Sheetal Garg           **
**                  Assistant Professor               **
**                  Phone No:9467863365               **
********************************************************
********************************************************
enter month no.
12
december

Output 3:

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