Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers.

Ex: If the input is:

5 2 4 6 8 10
the output is:

all even
Ex: If the input is:

5 1 3 5 7 9
the output is:

all odd
Ex: If the input is:

5 1 2 3 4 5
the output is:

not even or odd
Your program must define and call the following two functions. IsArrayEven returns true if all integers in the array are even and false otherwise. IsArrayOdd returns true if all integers in the array are odd and false otherwise.

bool IsArrayEven(int inputVals[], int numVals)

bool IsArrayOdd(int inputVals[], int numVals)





#include

#include



/* Define your function here */



int main(void) {



/* Type your code here. Remember to include the bool library*/



return 0;

}

Answers

Answer 1

Explanation:

Not sure what level that's at, or how you're expected to manage memory, so I'll write it in a "safe" manner and you can adjust accordingly.

Notably, I'm allocating memory dynamically at the moment.  If you're not used to that, you might want to change that.  Also, the c compiler I'm using (gcc) doesn't handle the bool type, so I used int.  You may need to change that.

Also, if you change it to use fixed arrays instead of malloc, realloc and free, then you don't need to include stdlib.h.

The code below builds successfully with gcc, so if you have any issues, it will be in translating to another compiler/language.

Answer:

#include <stdio.h>

#include <stdlib.h>

int isArrayOdd(int *inputVals, int numVals){

       int n, rval = 1;

       for(n = 0; n < numVals && rval; n++){

               rval &= inputVals[n] & 1;

       }  

       return rval;

}

int isArrayEven(int *inputVals, int numVals){

       int n, rval = 1;

       for(n = 0; n < numVals && rval; n++){

               rval &= 1 - (inputVals[n] & 1);

       }  

       return rval;

}

int main(void) {

       /*  

               I'm writing this to allow any quantity of numbers,

               using malloc to allocate the memory for them dynamically.

               You may want to modify this to match the level that your

               class is in.

       */

       int *numbers, quantity = 0, input;

       numbers = (int *) malloc(sizeof(int));

       printf("Please enter a number, or hit \"q\" to quit: ");

       while(scanf("%i", &input) == 1){

               quantity++;

               numbers = (int *) realloc(numbers, quantity * sizeof(int));

               numbers[quantity - 1] = input;

               printf("\nyou entered %i\n", numbers[quantity - 1]);

       }  

       if(isArrayOdd(numbers, quantity)){

               printf("all odd\n");

       }else if(isArrayEven(numbers, quantity)){

               printf("all even\n");

       }else{

               printf("not even or odd\n");

       }  

       free(numbers);

       return 0;

}

=================================================================

BONUS!    BONUS!    BONUS!    BONUS!    BONUS!    BONUS!    BONUS!

=================================================================

The inefficiency of the logic dictated in the assignment drove me nuts, so here's one that's ridiculously simpler and does exactly the same job:

#include <stdio.h>

int main(void) {

       int input, oddEven = -1;

       printf("Please enter a number, or hit \"q\" to quit: ");

       while(scanf("%i", &input) == 1){

               printf("\nyou entered %i\n", input);

               if(oddEven == -1){

                       oddEven = input & 1;

               }else if(oddEven != (input & 1)){

                       oddEven = 2;

               }

       }

       switch(oddEven){

               case 0:

                       printf("The numbers are all even\n");

                       break;

               case 1:

                       printf("The numbers are all odd\n");

                       break;

               case 2:

                       printf("The numbers are both odd and even\n");

                       break;

               default:

                       // should never happen

                       printf("Something odd happened.");

       }

       return 0;

}


Related Questions

An algorithm can have an output and an outcome
A) True
B) False

Answers

I believe it’s false 99%sure

do you humans know what math is?

Answers

Some do some dont Albert einstein has the biggest brain :))

How do Agile and DevOps interrelate?

Answers

Answer:

DevOps is a practice of bringing development and operations teams together whereas Agile is an iterative approach that focuses on collaboration, customer feedback and small rapid releases.

set screw compression and indenter are all types of
a. compression couplings.
b. threaded connectors.
C. rain-tight fittings.
D. threadless connecters and couplings.

Answers

nAnswer:

A.

Explanation:

The compression couplings can be defined as a set of screw, compression, and indenter. A compression fitting is a type of coupling used to connect pipes. A compression couplings is used to connect fixtures and tubings.

It contains screw, compression, and indenter. Therefore, option A is correct answer.

Answer:

dude above me capping its threadless connectors stay strong king

Explanation:

vector graphics are composed of solid __________,curves and other __________ shapes​

Answers

Answer:

Lines; geometric.

Explanation:

Graphic design can be defined as an artistic process used for the creation of art works such as logos.

In the creation of various graphic files such as in 2-D or 3-D we can use a variety of software applications or programs such as Blender basics, Adobe photoshop, illustrator, Coreldraw, etc.

Graphic design involves the use of vector graphics, bitmap graphics or raster graphics.

Vector graphics are composed of solid lines, curves and other geometric shapes that are typically defined by series of mathematical instructions. Thus, vector graphics can be scaled to a smaller or larger size without any change in its quality.

PLEASE HELP TAKING TEST NOW!!! Of the following websites, the least trustworthy is one that (1 point)
has the author's name and the current year as the date the site was posted
O has in-depth information and has a .gov URL
O has photographs and a copyright date of 1997
O has a company logo and the results of independent research

Answers

Here's all the right answers.

1. What is the main purpose of a graphic organizer?

Answer: B

2. Which of the following website publishers would be considered an authoritative source about the cultures of ancient Mesopotamia?

Answer: C

3. Which of the following websites is the least biased?

Answer: D

4. Which of the following is true about graphic organizers?

Answer: A

5. Of the following websites, the least trustworthy is one that...

Answer: C

Question 3 of 10
What is one task of a system optimization tool?
A. Identifies which programs to begin automatically when you start
your computer
B. Downloads all free programs available to you on the Internet
C. Troubleshoots malfunctioning software, such as word processing
software
D. Troubleshoots malfunctioning hardware, such as a mouse or
keyboard

Answers

The OS optimization tool includes the ability to automate and help with some of the common clean up tasks that are tipically run just before using the prepared image. This includes system Clean up tasks and clearing information. Answer: A, identifies which programs to begin automatically when you start your computer.

Some routine cleanup procedures that are often performed right before using the produced image can be automated by the OS optimization tool, and it can also assist with these operations. Thus, option A is correct.

What one task of a system optimization tool?

One of the features of the Windows OS Optimization Tool for Horizon is the ability to automate and aid in a few of the routine cleanup procedures that are frequently performed just before employing the prepared image.

There are three parts to every optimization problem: an objective function, choice variables, and constraints.

The term “formulating an optimization concern” refers to the process of turning a “real-world” issue into the mathematical equations and variables that make up these three parts.

To make the image cleaner and ready for usage with Horizon, they comprise system cleanup procedures and information cleaning.

Therefore, This involves clearing information and performing system cleanup chores.

Learn more about optimization tool here:

https://brainly.com/question/24843744

#SPJ5

Hey system has defined specific Quetion that describe how signals are sent over connections. Which layer of the transmission control protocol model provides this function?

Answers

Complete Question:

A system has defined specifications that describe how signals are sent over connections. Which layer of the Transmission Control Protocol/Internet Protocol (TCP/IP) model provides this function?

Group of answer choices.

A. Transport

B. Network

C. Data link

D. Physical

Answer:

A. Transport

Explanation:

Transmission Control Protocol/Internet Protocol (TCP/IP) model is a standard communication protocol used for interconnecting network devices such as routers, switches, host computers and access points over the internet.

A system has defined specifications that describe how signals are sent over connections. The layer of the Transmission Control Protocol/Internet Protocol (TCP/IP) model that provides these functions is the transport layer.

The transport layer comprises of two (2) standard protocols and these are TCP and UDP.

TCP is an acronym for Transmission Control Protocol and it is one of the essential and important protocol of the internet protocol network. This simply means that, it is an essential part of the TCP/IP network. The TCP has a wide range of applications in the following areas, file transfers, world wide web, remote administration, e-mail, etc.

The TCP connection are mainly established in the network using the three-way handshake.

UDP is an acronym for user datagram protocol and it enables the transfer or exchange of data between network devices.

PHOTOSHOP IS A GRAPHICS EDITING PROGRAM CREATED WITH IMAGES KNOWN AS________ ​

Answers

Answer:

Adobe

Explanation:

A web feed:

A. runs a ticker tape of all your friends' comments on a social
networking site.
B. lists all the activity and postings that are occurring on a website.
C. alerts news watchers of a breaking story they can watch on TV or
online.
D. notifies users that new content has been added to a specific
website.

Answers

The best answer is D

Web feed notifies users that new content has been added to a specific website. Then the correct option is D.

What is a web feed?

The frequent regular update of the content or information given to the user through data format is known as a web feed.

It notifies users that new content has been added to a specific website.

Thus, the correct option is D.

More about the web feed link is given below.

https://brainly.com/question/11319715

#SPJ2

The current calendar, called the Gregorian calendar, was introduced in 1582. Every year divisible by four was declared to be a leap year, with the exception of the years ending in 00 (that is those divisible by 100) and not divisible by 400. For instance, the years 1600 and 2000 are leap years, but 1700, 1800, and 1900 are not. Write a program that requests a year as input and states whether it is a leap year. (Test the program on the years 2008, 2009, 1900, and 2000.)

Answers

Solution :

Public Function Is a Leap_Year(Year As_Integer) As Integer

'Dim Tor_F for local variable declaring if value is t/f.

Dim TorF As For Boolean

'Pre conditions: Year > 1581 and Year < 3000

If Year > 1581 And Year <> 1700 Or 1800 Or 1900 Then

IsLeapYear = Year / 4

Else

IsLeapYear = False

TorF = False

End If

End Function

Other Questions
Please help i am new here AS ALWAYS, DUE TODAY! Pls and thanks. NOTE- Legit answers only! Legit answers= Brainliest, 5.0 stars, and a Thanks. No one helped on the last one, so I had to repost. What does the old uncle say they should do Determine the slope of the line passing through the points (1, 2) and ( 2, 2). PLZ HURRY I WILL MARK BRAINLIESTWhy was Rosa Parks ordered to give up her seat on the bus? because the driver disliked her because she wasnt allowed to sit so that a black man could sit so that a white man could sit The Fifth Amendment to the Constitution, which protects citizens from the deprivation of property without the due process of law and requires just compensation for property taken for public use, is a key tenet of which of the following selections?Select one:A. economic freedomB. right of first refusalC. political freedomD. retributive justice What is the total measurement of the angels in a triangle? Emma is writing a program to encrypt text entered by a user. Only letters, spaces and punctuation marks can be encrypted. Each letter in the text is replaced by the letter three places further down the alphabet. A is replaced by D, b by e, Y by B, z by c. Spaces and punctuation marks are not changed. Complete the test plan below by stating, for each input data and expected outcome, the type of test and a reason for the test. Cuando haces ejercicios abdominales estas realizando un trabajo. Si haces el mismo numero de abdominales en la mitad de tiempo que acostumbras, como seria tu rendimiento en terminos de potencia comparandolo con el tiempo normal en que las haces? List adjectives that describe the emotions ofthe cartoon. Unit 5 Hw 5 all things algebra 2014 bottom questions Choose the compound sentence.Judy and Maria traveled to Boston, Massachusetts, together.He told her the truth, but she did not believe it.Billy is a descendant of the Earl of Lancaster.Warren played basketball, soccer, and tennis. Twenty-one more than three times a number is equal to the difference between 46 and twice the number. Find the number. In 2010, Kim-Ly earned $17.50 for 2 hours of work. Which table shows the relation ship between the number of hours worked and Kim-Lys total earnings, if her rate per hour is constant. Please help what is 80 less than x? Steven has 1/3 of package of biscuit mix left.He will use equal para of the leftover mix to make three watches of biscuits. If he uses all of the mix, what fraction of the original package will he use for each batch? What is: 7y + 2 < 5y + 12 what is (-9 - 6 x 5) x 10 = ? Read the excerpt from an 1868 speech to the Georgia state legislature. Then answer the question that follows."I hold that I am a member of this body. Therefore, sir, I shall neither fawn nor cringe before any party, nor stoop to beg them for my rights. Some . . . in the course of their remarks, took occasion to appeal to the sympathies of members on the opposite side. . . . I am here to demand my rights and to hurl thunderbolts at the men who would dare to cross the threshold of my manhood."Which individual MOST LIKELY delivered this speech?Group of answer choicesAlexander StephensBooker T. WashingtonW.E.B. Du BoisHenry McNeal Turner The base of the following pyramid is a square. If the surface area of the pyramid is 896 in^2, what is it's volume? Side base length is 14 and distance to middle is 7.