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
kirza4 [7]
3 years ago
9

LAB: Even/odd values in an array

Computers and Technology
2 answers:
forsale [732]3 years ago
7 0

Answer:

integers=[]

while True:

      number=int(input())

      if number<0:

       break

      integers.append(number)  

print("",min(integers))

print("",max(integers))Explanation:

Masja [62]3 years ago
4 0

Answer:

  1. #include <stdio.h>
  2. bool IsArrayEven(int inputVals[], int numVals){
  3.    int i;
  4.    for(i = 1; i < numVals; i++){
  5.        if(inputVals[i] % 2 != 0){
  6.            return false;
  7.        }
  8.    }
  9.    return true;
  10. }
  11. bool IsArrayOdd(int inputVals[], int numVals){
  12.    int i;
  13.    for(i = 1; i < numVals; i++){
  14.        if(inputVals[i] % 2 == 0){
  15.            return false;
  16.        }
  17.    }
  18.    return true;
  19. }
  20. int main()
  21. {
  22.     int my_input[] = {5, 2, 4, 6, 8, 10};
  23.     if(IsArrayEven(my_input)){
  24.         printf("all even");
  25.     }else if(IsArrayOdd(my_input)){
  26.         printf("all odd");
  27.     }else{
  28.         print("not even or odd");
  29.     }
  30. }  

Explanation:

Firstly, write two functions to check if the input array is all even or all odd (Line 3-22). The key idea is to use modulus operator to check if a number % 2 equal to 0, it is an even number, if not, it is an odd. So long as one of the number is odd in the isArrayEven function, the function shall return false (Line 7). If no odd value detected, it return true (Line 11). The similar code logic is applied to isArrayOdd function too.  

Then, we can call the two functions sequentially in the main program. If isArrayEven function return true, it display all even message (Line 28-29). If odd, display all odd (Line 30 -31). If neither, display not even or odd (Line 32-33).

You might be interested in
Def build_dictionary(string):
MissTica

Answer:

Follows are the code to this question:

def build_word_counter(string):#defining a method build_word_counter that accepts string as a parameter  

   d = dict()#defining d variable as a dictionary

   for x in string:#defining for loop that use string

       x = x.lower()#Use lower method  

       if not d.get(x):#defining if block that holds value in d variable

           d[x] = 1#use dictionary to hold value in 1

       else:#defining else block

           d[x] += 1#use dictionary to increment value by 1

   return d#return dictionary

print(build_word_counter(["Like","like","LIKE"]))#use print method to call method

def build_letter_distribution(string):#defining a method build_letter_distribution that accepts string variable

   d = dict()#defining d variable as a dictionary

   for i in string:#defining for loop to count string value

       for j in i:#defining for loop to hold string as number

           if not d.get(j):#defining if block that doesn't get value in dictionary  

               d[j] = 1#hold value in dictionary  

           else:#defining else block

               d[j] += 1#use dictionary to increment the dictionary value

   return d#return dictionary

print(build_letter_distribution(["Like","test","abcdEFG"]))#use print method to return its value

Output:

please find the attached file.

Explanation:

In the first program a method, "build_word_counter" is defined that accepts a string variable in its parameter, and inside the method, a dictionary variable "d" is defined that uses the for loop to hold string value and convert all value into lower case.

In the next step, a conditional statement is used that holds value in the dictionary and count its word value.

In the second program a method, "build_letter_distribution" is defined that holds string variable in its parameter, and inside the method, a dictionary variable "d" is defined that uses the two for loop and in if the block, it holds value in the dictionary and returns its value, and use print method to print its return its value.

4 0
3 years ago
Create a function called howManyUntil(stopNum) where stopNum is an integer from 0 and 99
uysha [10]

Answer:

i dont get it

Explanation:

6 0
3 years ago
8. Compare the advantages and disadvantages of using a smartphone rather than a laptop computer for creating a report.​
JulijaS [17]

Answer: the advantage of using a smartphone rather than a laptop computer is that you can talk to people across the world, call people, make texts, and get easy access to the internet. but the disadvantages are that a lot of people stay inside their house because of phones, not getting enough exercise.

Explanation:

3 0
3 years ago
Understanding the intended audience of a media piece will help the reader :
Sati [7]

Answer:

It depends

Explanation:

..

6 0
3 years ago
Describe the steps that transform a program written in a high-level language such as C into a representation that is directly ex
Alla [95]

Answer:

First, you would want to translate from C-language Program (in text format) into the assembly language Program (still in text format, but in the corresponding architecture of the computer where the program will be run). The software tool you will use for this step is Compiler.

Then you would translate from the assembly language program (text format) into Machine Code Program (in binary format). The software tool used for this step would be Assembler.

7 0
2 years ago
Other questions:
  • Input numbers and segregate them by placing their values into even or odd vectors based upon their value being even or odd. Then
    12·1 answer
  • What is an abstract class? (Points : 2) A generalized class used only to create related derived classes
    6·1 answer
  • I bought an iPhone 6s Plus with 16gb three days ago and I found out that it s very little space for my liking and I want to exch
    10·1 answer
  • Write a program with a loop that lets the user enter a series of positive integers. The user should enter −1 to signal the end o
    7·1 answer
  • A photo's color intensity can be modified by changing the brightness and content.
    9·1 answer
  • The ____ operator executes one of two expressions based on the results of a conditional expression. Group of answer choices
    15·2 answers
  • What law made it illegal to spread contraceptive information and devices?
    6·1 answer
  • What are the disadvantages of using photo editing software in photography?
    14·1 answer
  • Learning how to use word processing and spreadsheets, and creating presentations are all considered __________ computer skills.
    15·2 answers
  • What is science worksheet answers name the three features that make science different from other human endeavors?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!