Write a C program that does the following: Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1 and 100 inclusive Then, creates two more 100-element arrays, one holding odd values and the other holding even values (copied from the original array). These arrays might not be filled completely. Prints both of the new arrays to the console.

Answers

Answer 1

Answer:

Following are the code to this question:

#include <iostream>//header file

using namespace std;

int main()//main method

{

   int axb[100];//defining 1-array of 100 elements

   int odd_axb[100], even_axb[100];//defining two array that holds 100-elements

   int i,size=0,size1=0;

   for(i = 0; i < 100; i++)//defining for loop to assign value in array

   {

       axb[i] = rand() % 100 + 1;//using rand method to assign value with random numbers between 1 and 100

   }

   for(i = 0; i < 100; i++)//defining for loop that seprates array value in odd and even array

   {

       if(axb[i] % 2 == 0)//checking even condition  

       {

           even_axb[size++] = axb[i];//holding even number

       }

       else//else block

       {

           odd_axb[size1++] = axb[i];//holding Odd number

       }

   }

   //printing values

   cout << "Odd array: ";//print message  

   for(i = 0; i <size1; i++)//use for loop for print odd numbers

   {

   cout << odd_axb[i]<<" ";//printing values

   }

   

   cout <<"\n\n"<< "Even array: ";//print message

   for(i = 0; i <size; i++)//use for loop for print even_axb numbers

   {

       cout << even_axb[i] << " ";//printing values

   }

   return 0;

}

Output:

Odd array: 87 87 93 63 91 27 41 27 73 37 69 83 31 63 3 23 59 57 43 85 99 25 71 27 81 57 63 71 97 85 37 47 25 83 15 35 65 51 9 77 79 89 85 55 33 61 77 69 13 27 87 95  

Even array: 84 78 16 94 36 50 22 28 60 64 12 68 30 24 68 36 30 70 68 94 12 30 74 22 20 38 16 14 92 74 82 6 26 28 6 30 14 58 96 46 68 44 88 4 52 100 40 40

Explanation:

In the above-program, three arrays "axb, odd_axb, and even_axb" is defined, that holds 100 elements in each, in the next step, three integer variable "i, size, and size1" is defined, in which variable "i" used in the for a loop.

In the first for loop, a rand method is defined that holds 100 random numbers in the array, and in the next, for-loop a condition statement is used that separates even, odd number and store its respective array, and in the last for loop, it prints its store values  


Related Questions

whats this oh _____
what is it
A) jane
B) juan.
C)juan
D) horse

Answers

Answer:

juan duhhhhh hehehe

Explanation:

The ABC box company makes square puzzle cubes that measure 4 inches along each edge. They shipped the cubes in a box 8 in x 12 in x 16 in. How many cubes can they ship in the box?

Answers

Answer: They can ship 32 puzzle cubes in the box.

Explanation: So the volume of each puzzle cubes = side³

=(4)³ cubic inches.

Then the volume of the box is= (8×12×16) cubic inches.

(8×12×16)/4^3= 32

Write a class called Dragon. A Dragon should have a name, a level, and a boolean variable, canBreatheFire, indicating whether or not the dragon can breathe fire. The class should have getter methods for all of these variables - getName, getLevel, and isFireBreather, respectively.

Answers

Answer: A dragon name could be name Holls and at level 14 and can breathe fire

Explanation:

Other Questions
Which statement below best describes the differences between hormones and neurons?A) hormones are faster communication used by plants and animals; neurons are slow communication used by animals onlyb) hormones are faster communication used by plants and animals; neurons are slow communication used by plants onlyc) nhormones are slower communication used by plants and animals; neurons are fast communication used by animals onlyd) hormones are slower communication used by plants and animals; neurons are fast communication used by plants only Which expression represents the sentence "five times a number, n"? what is this one pls help me out What is a theme of Twelfth Night?1. Telling lies rarely hides the truth. 2. Outer appearances can be misleading.3. Seeking revenge is never justified.4. With experience comes wisdom. Which term describes the complete set of processes carried out by an organism in order to sustain life?vrefers to the set of chemical processes carried out by an organism In order to sustain life. Digestion is a form ofactivity. - Colin invests 1100 into his bank account.He receives 5% per year simple interest.How much will Colin have after 3 years?Give your answer to the nearest penny where appropriate. why is digital better then analog music I NEEED TO GET THIS RIGHT PLS ANSWERRRRR. ILL GIVE YOY ALOT OF POINTS AND A BRAINLYIST!!! When Samantha travels south from her hometown in Philadelphia, she often takes on a Southern accent anduses words and phrases unique to the south when speaking with others. This is an example of the a salesperson earns a commission of 312$ for selling 2600 in merchandise The ACE Equity Fund has an expected return E[r] of 11.830% and the ZQR Bond Fund has an expected return E[r] of 6.690%. A portfolio comprised of 3% ACE and 97% ZQR would have an expected return of __________%. (percent, rounded three places after decimal) The students meet with a team of geologists that is studying the rock layers at the first roadcut. The geologists find fossils of the same kind of organisms in layers P and Q. Which of the following conclusions about the layers at the second roadcut is most likely trueA) The fossil found at the first roadcut should only be found in layers P and Q at the second roadcutB)The fossil found at the first roadcut should be found in layers P, N, and Q at the second roadcutc) The fossil found at the first roadcut should only be found in layer N at the second roadcut D) The fossil found at the first roadcut should not be found in any layers at the second roadcut. Lin runs 5 laps a track in six minutes how many minutes per lap is that Please help meIf you correct answer, I will give you Brainiest.Due 10:00 Pm Please Plzzzzzzzzzzzzzzzz Helo Answer correct please but It can tell if the answer is wrong How was the labor movement connected to the first women's rightsmovement? Slope = 1.75; (10, 16.5) Hal earns n dollars per hour. Next month hewill receive a 296 raise in pay per hour. Theexpression n +0.02n is one way to representHal's pay per hour after the raise Write anequivalent simplified expression that willrepresent his pay per hour after the raise. HELP!! I dont get it please help 1. What is the probability of rolling a 4 on a number cube and flipping tails on a coin? 2. Event A: Spinner #1 lands on red.Event B: Spinner #2 lands on yellow.3. Jake rolls two number cubes. What is the probability that both numbers are greater than 4?4. A bag has 2 red marbles, 1 blue marble and 4 gold marbles. What is the probability of drawing two gold marbles, if the first marble is replaced after it is drawn?5.A bag held 3 white marbles, 1 orange marble, and 2 green marbles. Anna drew a white marble and did not replace it. What is the probability of drawing a green marble next?IF YOU DONT KNOW THE ANSWER DONT ANSWER!! ANSWER ALL QUESTIONS