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

What are the values of a[k] and a[k+1] after code corresponding to the following pseudocode runs?

Computers and Technology
2 answers:
valentina_108 [34]3 years ago
7 0

Answer:

Option B: a[k] = 20, a[k + 1] = 10 is the correct answer.

Explanation:

We will dry run the pseudocode line by line and monitor the values stored in elements to get the final answer.

We have three elements to be used in the code.

a[k] , a[k+1] and temp

a[k] = 10;

This line assigns value 10 to a[k]

a[k+1] = 20;

This line assigns value 20 to a[k+1]

temp = a[k];

This line will assign the value in a[k] to temp i.e. we have following values currently stored at the three locations a[k] = 10, a[k+1] = 20 and temp = 10

a[k] = a[k+1] ;

This line of code assigns the value of a[k+1] to a[k] which means now we have a[k] = 20 , a[k+1] = 20 and temp =10

a[k+1] = temp ;

This line will assign the value in temp to a[k+1] which means now we have

a[k] = 20 , a[k+1] = 10 and temp = 10

Hence, looking at the final values in a[k] and a[k+1] it can be concluded that

Option B: a[k] = 20, a[k + 1] = 10 is the correct answer

Whitepunk [10]3 years ago
4 0

Answer:

Option B: a[k] = 20, a[k + 1] = 10 is the correct answer.

Explanation:

We will dry run the pseudocode line by line and monitor the values stored in elements to get the final answer.

We have three elements to be used in the code.

a[k] , a[k+1] and temp

a[k] = 10;

This line assigns value 10 to a[k]

a[k+1] = 20;

This line assigns value 20 to a[k+1]

temp = a[k];

This line will assign the value in a[k] to temp i.e. we have following values currently stored at the three locations a[k] = 10, a[k+1] = 20 and temp = 10

a[k] = a[k+1] ;

This line of code assigns the value of a[k+1] to a[k] which means now we have a[k] = 20 , a[k+1] = 20 and temp =10

a[k+1] = temp ;

This line will assign the value in temp to a[k+1] which means now we have

a[k] = 20 , a[k+1] = 10 and temp = 10

Hence, looking at the final values in a[k] and a[k+1] it can be concluded that

Option B: a[k] = 20, a[k + 1] = 10 is the correct answer

You might be interested in
Write a small program that takes in two numbers from the user. Using an if statement and an else statement, compare them and tel
kap26 [50]

What code is it java, HTML,C++ or lua?  be specific.

4 0
3 years ago
Read 2 more answers
You are given two arrays of integers a and b of the same length, and an integer k . We will be iterating through array a from le
rodikova [14]

Answer:

#include <iostream>

using namespace std;

int main(){

   int arr1[5], arr2[5], k = 7;

   arr1 = {1,3,5,3,6}

   arr2 = {1,3,2,4,4}

   int reverseA2[5];

   for (int x = 5; x > 0; x++){

       reverseA2[5-x] = arr2[x-1];

   }

   for (int i = 0; i < 5; i++){

       if ( arr1[i] + reverseA2[i] < k){

           cout<< arr1[i] << " , "<<reverseA2[i];

       }

   }

}

Explanation:

The C++ source code prints a pair of values from the arr1 and reverse arr2 arrays whose sum is less than the value of the integer variable value k.

4 0
3 years ago
Leo needs to consolidate data in multiple worksheets by performing a calculation across all worksheets on the same cells.
wolverine [178]
A do you think is the answer
4 0
3 years ago
Read 2 more answers
Help with some questions. Thank you!
Oksana_A [137]

Answer:

1. E: II and III only

2. A: (int)(Math.random() * (upper − lower) ) + lower

3. A: The value of answer is N

4. E: while( !(userGuess == secretNumber) && numGuesses <= 15 )

5. C: 21

Explanation:

1. Which of the following is equivalent to while(userGuess != secretNumber)?

I. while( userGuess < secretNumber && userGuess > secretNumber)  

NO - This will test until the userGuess is smaller AND greater than the secretNumber, at the same time... so that condition will never be true.

II. while( userGuess < secretNumber || userGuess > secretNumber)

YES - This will test the value of userGuess and see if it's smaller OR greater than secetNumber.  So, it will loop until the user guesses right.

III. while( !(userGuess == secretNumber) )

YES, this will negate the match with the secretNumber.  In order words, if it's not a match, it will return true... so the loop will run until it finds a false condition (a match).

As you can see, only II and III are valid.

2.  If the lower limit were inclusive and the upper limit exclusive, which expression would properly generate values for the secret number?

A: (int)(Math.random() * (upper − lower) ) + lower

Since the lower limit is INCLUSIVE, we mustn't add one to the lower limit.  Also, the Math.random() function returns a value that matches our needs; it returns a value between [0,1[ (meaning the 0 is included, but not the 1).

Assuming the (int) caster does return only the integer portion doing a round down of the result, we'll be perfect.

3. What conclusion can be made about the state of the program when the while loop terminates?

while(!answer.equals( "N"))

{.....

A: The value of answer is N

The condition in the loops reads as "While the negation of the answer being 'N', loop".  If the answer equals 'N' then the method should return true... which will be negated by the '!' operator, causing the condition to be false. Thus we know that if the loop ends, the value of answer contains 'N', any other value will keep the loop going.

4. Assuming numGuesses is initialized to 1, how would the while statement be modified to include an extra criterion limiting the number of guesses to 15?

E: while( !(userGuess == secretNumber) && numGuesses <= 15 )

This modified condition will first test to see if the user has guessed the secretNumber (if he has, the first sub-parenthesis will be true... so the left side of the && operator will be false due to the negation operator.  The right side of the && operator will check to see how many tries have been attempted. Since the counter starts at 1, it needs to go up to 15 inclusively... so the <= is the right comparison operator.

5. After execution of the following code segment, what will be displayed?

int x = 1;

while(x < 18)

{

x += 5;

}

System.out.println(x);

C: 21

The x variable is initialized with 1... then enters the loop, in which it is incremented by 5 at each passage.

So after first passage, x = 6

After second passage, x = 11

After third passage, x = 16

After fourth passage, x = 21

Cannot enter the loop again because 21 > 18.

So, it will print out the value of 21.

3 0
3 years ago
Write a program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name wil
sergeinik [125]

Answer:

// program in Python

# function to find grade

def grade(t_score):

   #grade A

   if t_score >=90:

       return 'A'

       #grade B

   elif t_score >=80 and t_score <90:

       return 'B'

   #grade C

   elif t_score >=70 and t_score <80:

       return 'C'

   #grade D

   elif t_score >=60 and t_score <70:

       return 'D'

   #grade F

   else:

       return 'F'

# function to find average score

def calc_average(test_score):

   #variable to find sum

   total = 0

   for i in range(len(test_score)):

       #calculate total score

       total = total + test_score[i]

   # find average

   return total/float(len(test_score))

#array to store score

test_score = []

#read name of student

name = input("Enter student's name: ")

for i in range(8):

   #read score

   t_score = int(input("Enter the score {}: ".format(i+1)))

   #add score to array

   test_score.append(t_score)

#call function to find Average

averageScore = calc_average(test_score)

#print name of Student

print("Student Name: ", name)

#print each Score

for i in range(len(test_score)):

   #print each Score and Grade

   print("Score: ",test_score[i], "Letter Grade: ",grade(test_score[i]))

# print Average Score

print("Average Score: ", averageScore)

Explanation:

Read name of student from user.Then read 8 test scores from user. Call the function grade() to find the grade of a test score.Call the function calc_average() to  find the average score of all test.Print each score and corresponding grade and print  average score.

Output:

Enter student's name: Sam                                                                                                  

Enter the score 1: 45                                                                                                      

Enter the score 2: 98                                                                                                      

Enter the score 3: 67                                                                                                      

Enter the score 4: 86                                                                                                      

Enter the score 5: 60                                                                                                      

Enter the score 6: 77                                                                                                      

Enter the score 7: 92                                                                                                      

Enter the score 8: 32                                                                                                      

Student Name:  Sam                                                                                                        

Score:  45 Letter Grade:  F                                                                                                

Score:  98 Letter Grade:  A                                                                                                

Score:  67 Letter Grade:  D                                                                                                

Score:  86 Letter Grade:  B                                                                                                

Score:  60 Letter Grade:  D                                                                                                

Score:  77 Letter Grade:  C                                                                                                

Score:  92 Letter Grade:  A                                                                                                

Score:  32 Letter Grade:  F                                                                                                

Average Score:  69.625  

3 0
3 years ago
Other questions:
  • Is motherboard a:<br><br> A.operating system<br> B.software<br> C.hardware<br> D.input device
    11·1 answer
  • If you turn your volume to loud on u'r headphones can it break the sound quality of the speaker?
    9·2 answers
  • A written guarantee to fix or replace an item is called a _____.
    5·2 answers
  • What happens if the cursor is in the last cell in a table and you press Tab?
    10·1 answer
  • Hi weegy, what is the latest android os?
    9·1 answer
  • Which module is missing from most expert systems? a. Knowledge base subsystem b. Inference engine c. User interface subsystem d.
    5·1 answer
  • NEED FIVE QUESTIONS ANSWERED!!!
    7·1 answer
  • (20points)
    6·1 answer
  • David is selling his art work. He wants to figure out how much he should charge for each painting to make a 20 percent profit. H
    10·1 answer
  • How do motion sensors determine in simation
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!