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
- Enter month number as 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”);
- }
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