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
Recall that with the CSMA/CD protocol, the adapter waits K. 512 bit times after a collision, where K is drawn randomly. a. For f
julia-pushkina [17]

Complete Question:

Recall that with the CSMA/CD protocol, the adapter waits K. 512 bit times after a collision, where K is drawn randomly. a. For first collision, if K=100, how long does the adapter wait until sensing the channel again for a 1 Mbps broadcast channel? For a 10 Mbps broadcast channel?

Answer:

a) 51.2 msec.  b) 5.12 msec

Explanation:

If K=100, the time that the adapter must wait until sensing a channel after detecting a first collision, is given by the following expression:

  • Tw = K*512* bit time

The bit time, is just the inverse of the channel bandwidh, expressed in bits per second, so for the two instances posed by the question, we have:

a) BW  = 1 Mbps = 10⁶ bps

⇒ Tw = 100*512*(1/10⁶) bps = 51.2*10⁻³ sec. = 51.2 msec

b) BW = 10 Mbps = 10⁷ bps

⇒ Tw = 100*512*(1/10⁷) bps = 5.12*10⁻³ sec. = 5.12 msec

5 0
3 years ago
An employee mentions that opening a large document file is taking longer than usual. The desktop support technician suspects tha
kumpel [21]

Answer:

Perform data backup on the work computer

Explanation:

It is very important that at every point in time that a technician will perform a maintenance, repair, or troubleshooting. the data on the work computer should be backed up to avoid loss. This is done to avoid data loss resulting from failure from hardware or software, backup provides copy of critical data immediately the maintenance is done, therefore backup is very important before any troubleshooting is done.

8 0
3 years ago
What does filtering a record do?
Vedmedyk [2.9K]

Answer:

It sorts all the data in record.

Explanation:

third one is verified

3 0
2 years ago
*When a computer programmer is finished writing or developing a program, what has to happen first before the computer can unders
Alenkinab [10]

Answer:

C. The source code has to be translated into object code.

5 0
2 years ago
C. There are two types of computer on the basis of size. true or false​
Veronika [31]

Answer:

False

Explanation:

Different factors, such as processing power, information processing, and the component (CPU) utilised in computers, are used to classify computers. Micro-computers, Mini-computers, Main-frame computers, and Super-computers are divided into four categories based on the components utilised and functionality of the computers.

4 0
2 years ago
Other questions:
  • Write a program that inputs a line of text and uses a stack object to print the line reversed.
    14·1 answer
  • Write a method maxMagnitude() with two integer input parameters that returns the largest magnitude value. Use the method in a pr
    9·1 answer
  • Drag the correct type of update to its definition.
    14·1 answer
  • Port explorers ​are tools used by both attackers and defenders to identify (or fingerprint) the computers that are active on a
    6·1 answer
  • Please help!!!! will mark brainliest!!
    7·2 answers
  • What type of network is the internet
    10·1 answer
  • When doing a Risk assessment, what is one of the most important things to do?
    8·2 answers
  • What is the difference between front-end and back-end?
    14·1 answer
  • What instructions would a computer have the hardest time completing correctly
    12·1 answer
  • The _____ constraint assigns a value to an attribute when a new row is added to a table
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!