Write a complete program to do the following Read in a numbe

Write a complete program to do the following: Read in a number. the number represents the months of the year (1 - Han., 2 = Feb., 3 = March, etc...) Given a number of a month (1-12), Print the name of the month (or an error message indicating an illegal month number). Give the algorithm, and source code.

Solution

//Algorithm

1. Input the number of month in the integer number.

2. Compare the number with digit 1-12.

3. if matches with anyone

4. display the respective month the switch case.

5. else if not matches with single case

6. Display illegal moth.

7. Exit.

// Source Code

#include<stdio.h>
void main()
{
        int month;
        printf(\"Enter the month\ \");
        scanf(\"%d\",&month);
        switch(month)
        {
                case 1:
                        printf(\"January\ \");
                        break;
                case 2:
                        printf(\"Feburay\ \");
                        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(\"Novemeber\ \");
                        break;
                case 12:
                        printf(\"December\ \");
                        break;    
                default:
                        printf(\"illegal month number\ \");
        }     
}

 Write a complete program to do the following: Read in a number. the number represents the months of the year (1 - Han., 2 = Feb., 3 = March, etc...) Given a nu
 Write a complete program to do the following: Read in a number. the number represents the months of the year (1 - Han., 2 = Feb., 3 = March, etc...) Given a nu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site