Question
Create a source file homework2.c and write code that generates a table of numbers from 0 to the maximum number given by the user. The
Create a source file homework2.c and write code that generates a table of numbers from 0 to the maximum number given by the user. The table has a column telling if each number is even or odd. The user interface will ask the user for the maximum number to print.
Here is an example of the output. You must print a brief description of the program at the beginning of the output. In this case, the user gave 15 as the maximum number, and the program prints 0 through 15, with the Odd/Even column.
User Interface
-
Define a user_interface function that requests the user to enter a maximum number.
int user_interface();
-
This function must be called by main.
-
It must show a brief introductory message explaining your program.
Invalid Inputs
-
If the given value is a character or string, the user_interface must display an error message AND prompt the user to enter an integer. You only need to test for the input of characters and integers. You do not have to worry about floats being entered. Also, you can accept a number followed by letters, e.g., 123abc as far as you can correctly take the number part 123 as an input.
-
If the given number is less than or equal to 0, user_interface must display an error message AND prompt the user to enter a positive integer.
-
After the program prompts the user to enter a valid input, it must NOT exit. (it will ask the user for input until the user gives a valid input.)
Function to check if the number is even
-
Define a function is_even with the following prototype:
int is_even(int);
-
The is_even function takes an integer and returns 1 if the number is even. Otherwise, it returns 0.
Print function
-
Define a print_table function that uses a for-loop to generate a table, starting from 0 to the given maximum number, with the Odd/Even column. (see the sample above)
void print_table(int);
-
This function must be called by main.
-
The table must be formatted. (see the sample above)
-
Columns must be right-aligned.
Enter maximum number to show: 15 Number Odd/Even Even 1 Odd 2 Even 3 Odd 4 Even 5 Odd 6 Even 7 Odd 8 Even 9 Odd 10 Even 11 Odd 12 Even 13 Odd 14 Even 15 Odd
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started