Question

In: Computer Science

Write a C program that reads an integer value. Assume it is the number of a...

Write a C program that reads an integer value. Assume it is the number of a month of the year; print out the name of that month (Hint: months need to be captured in an array).

Solutions

Expert Solution

Implement theprogram as follows:

  1. declare month_num to store month number
  2. declare 2-dimensional array to store month names, array index starts from 0. months[0] returns "January" and months[11] returns "December".
  3. ask the user to enter a month number
  4. read number from user
  5. Print month name corresponding to month_num as months[month_num-1]

Program:

#include <stdio.h>

int main()
{
    int month_num;                              /* declare month_num to store month number */
    char months[12][20] = {                     /* declare 2-dimensional array to store month names */
        "January", "February",
        "March", "April", 
        "May", "June",
        "July", "August",
        "September", "October",
        "November", "December"
    };
    
    printf("Enter the number of a month : ");   /* ask the user to enter a month number */
    scanf("%d", &month_num);                    /* read number from user */
    
    
    printf("Month : %s", months[month_num-1]);  /* Print month name corresponding to month_num */
    

    return 0;
}

Screenshot:

Output:

Please don't forget to give a Thumbs Up.


Related Solutions

In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
In c++, write a program that reads a string consisting of a positive integer or a...
In c++, write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format.
The Sum and The Average In C++, Write a program that reads in 10 integer numbers....
The Sum and The Average In C++, Write a program that reads in 10 integer numbers. Your program should do the following things: Use a Do statement Determine the number positive or negative Count the numbers of positive numbers, and negative Outputs the sum of: all the numbers greater than zero all the numbers less than zero (which will be a negative number or zero) all the numbers Calculate the average of all the numbers. The user enters the ten...
who to write a program c++ that reads in an integer between 0 and 1000 and...
who to write a program c++ that reads in an integer between 0 and 1000 and adds all the digits in the integer?
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
Write a C/C++ program which reads in a list of process names and integer times from...
Write a C/C++ program which reads in a list of process names and integer times from stdin/cin and simulates round-robin CPU scheduling on the list. The input is a list of lines each consisting of a process name and an integer time, e.g. ProcessA 4 ProcessB 10 Read the list until end of transmission (^d). You should read the list and represent it in a linked list data structure. You should use the alarm system call to schedule a timer...
Using Python. Write a program that reads a sequence (unknown number of inputs) of integer inputs...
Using Python. Write a program that reads a sequence (unknown number of inputs) of integer inputs and prints the number of even and odd inputs in the sequence. please explain. Thanks
Write a Python program that reads an integer and prints how many digits the number has,...
Write a Python program that reads an integer and prints how many digits the number has, by checking whether the number is ≥10,≥100,≥1000, and so on (up to 1,000,000). Your program should also identify if a number is negative.
Write a program that reads n integer values. If a negative value is entered, we want...
Write a program that reads n integer values. If a negative value is entered, we want to terminate the input, i.e., exit from the loop. If a zero value is entered, we want to ignore it and read the next value. Any strictly positive values (greater or equal zero) are to be totaled. Print the number of values read, the number of values totaled and the total. If a negative value is entered, print an error message before terminating the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT