1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nordsb [41]
3 years ago
6

In this chapter, you saw an example of how to write an algorithm that determines whether a number is even or odd. Write a progra

m that generates 100 random numbers and keeps a count of how many of those random numbers are even, and how many of them are odd.]

Computers and Technology
2 answers:
vagabundo [1.1K]3 years ago
8 0

Answer:

// Program is written in Java Programming Language

// Comments are used for explanatory purpose

// Program starts here

public class RandomOddEve {

/** Main Method */

public static void main(String[] args) {

int[] nums = new int[100]; // Declare an array of 100 integers

// Store the counts of 100 random numbers

for (int i = 1; i <= 100; i++) {

nums[(int)(Math.random() * 10)]++;

}

int odd = 0, even = 0; // declare even and odd variables to 0, respectively

// Both variables will serve a counters

// Check for odd and even numbers

for(int I = 0; I<100; I++)

{

if (nums[I]%2 == 0) {// Even number.

even++;

}

else // Odd number.

{

odd++;

}

}

//.Print Results

System.out.print("Odd number = "+odd);

System.out.print("Even number = "+even);

}

yarga [219]3 years ago
3 0

Answer:

Complete python code along with comments to explain the whole code is given below.

Python Code with Explanation:

# import random module to use randint function

import random

# counter variables to store the number of even and odd numbers

even = 0

odd = 0

# list to store randomly generated numbers

random_num=[]

# A for loop is used to generate 100 random numbers

for i in range(100):

# generate a random number from 0 to 100 and append it to the list

   random_num.append(random.randint(0,100))

# check if ith number in the list is divisible by 2 then it is even

   if random_num[i] % 2==0:

# add one to the even counter

        even+=1

# if it is not even number then it must be an odd number

   else:

# add one to the odd counter

        odd+=1

# finally print the count number of even and odd numbers

print("Total Even Random Numbers are: ",even)

print("Total Odd Random Numbers are: ",odd)

Output:

Total Even Random Numbers are: 60

Total Odd Random Numbers are: 40

Total Even Random Numbers are: 54

Total Odd Random Numbers are: 46

You might be interested in
You have a 20-bit network part and a 4-bit subnet part. How many hosts can you have per subnet?
Ymorist [56]

Answer:

tiddies

Explanation:

sukk

3 0
3 years ago
A hard drive cannot be partitioned until the device _________ is set.
Elza [17]
Partition(ed) is the answer
8 0
3 years ago
Read 2 more answers
The photographer for "The Migrant Mother" photograph used _______________, which is a technique that would be considered unethic
d1i1m1o1n [39]

Answer:

The technique used by the photographer which would be considered unethical today is:

Stage Managing

Explanation:

  • The Migrant Mother is a famous that was captured by the photographer named Dorothea Lange. This photograph was taken during the era of great depression that shows the misery of a women as well as her courage.
  • The photographer used the stage managing technique because the women in the photograph purposefully posed for the picture in order to let others know about their plight. She wanted to develop awareness as well as wanted the Government to help farmers.
  • The name of the women in the picture is Florence Owens Thompson and she was a mother of seven children. She lived in California.

8 0
3 years ago
Read 2 more answers
File formats are linked to certain programs.<br><br> True<br> False
Lostsunrise [7]
What was the answer?
7 0
3 years ago
Read 2 more answers
From the Start screen (on Excel), you can
Alex
I think (a) is the answer because this is the screen that it should open when u use it

6 0
3 years ago
Read 2 more answers
Other questions:
  • Please help me ! All you do is just put it it all in your own words ! Please this is for my reported card!i don't know how to pu
    15·1 answer
  • A virus is a self-replicating program that produces its own code by attaching copies of it into other executable codes.
    7·1 answer
  • We will pass in a value N. Write a program that outputs the complete Fibonacci sequence for N iterations. Important: If N is 0,
    13·1 answer
  • Who found the first computer bug in 1947, and invented the concept of a compiler in 1952
    6·1 answer
  • Create a function called is_list_empty that takes a single argument of type list. Your function should return True if the list i
    7·1 answer
  • Write a programmer defined function that compares the ASCII sum of two strings. To compute the ASCII sum, you need to compute th
    6·1 answer
  • Which factor is NOT used to determine who can be let go during a downsizing?
    8·2 answers
  • Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter.
    6·1 answer
  • User defined blocks of code can be created in
    13·1 answer
  • write a function that takes two integer arrays as input return true if any two of the numbers in the first array input add up to
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!