Thursday, 11 September 2014

How to get month name from month number in C Language program

This C program will let you know about “how to get month name from month number?”. This C source code is coming under the part of C beginners guide. Feel free to use this code or if you can just contribute as a program writer.

PRINT MONTH NAME IN C
Print month name in C program is used to print out the entered number value will be in month name by using switch statement. It executes the first condition and compare with all the case values. If it doesn’t match with any case then it will print a default value as wrong input.

//Header files
#include<stdio.h>
#include<conio.h>
 
void main()
{
    //Program variables
    int months;
 
    clrscr(); //function to clear previous output
 
    printf("Enter the month number(1-12) : "); //Display function
    scanf("%d",&months); //Getting value function
 
    switch(months) //Switch statement
    {
        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("incorrect Input");
        }
    getch();
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.