Question

In: Computer Science

B. Manually analyze and debug the following logic and programming code. Write in the result column,...

B. Manually analyze and debug the following logic and programming code. Write in the result column, the value of the result variable when the variables i and j have the values ​​indicated in each row of the table (6 pts.). In the event that the result cannot be calculated, state it and the reason.

Option Explicit

Sub Calc ()

Dim i As Integer, j As Integer, n As Integer
Dim result As Integer

i = 0
j = 0
n = 4
result = 0

For i = 1 to n
For j = 1 to n
result = result + (2 * i * j)
Next j
Next i

End Sub

i j result
1 1
2 3
3 5

Solutions

Expert Solution

The correct result is given in the below screenshot:

Explanation:

The initial value of the result is 0.

For i = 1 and j = 1, the value of result will be = 0 + (2 * 1 * 1)

= 0 + 2

= 2

So, the result in first row will be 2.

For i = 2 and j = 3, the value of result will be = result + (2 * 2 * 3)

The value of the result will be calculated starting from the first iteration as given below:

In the first iteration, the value of the result will be = 2
In the second iteration, the value of the result will be = 6
In the third iteration, the value of the result will be = 12
In the fourth iteration, the value of the result will be = 20
In the fifth iteration, the value of the result will be = 24
In the sixth iteration, the value of the result will be = 32
In the seventh iteration, the value of the result will be = 44

For i = 2 and j = 3, the value of result will be = 32 + (2 * 2 * 3)

= 32 + 12

= 44

So, the result in the second row will be 44.

For i = 3 and j = 5, the value of the result can't be calculated because the value of j is greater than n.

The value of j will be 1, 2, 3, and 4 only.

So, the result can't be calculated for i=3 and j=5.


Related Solutions

Write the VERILOG code for an arithmetic/logic unit (ALU) following , and can be tested in...
Write the VERILOG code for an arithmetic/logic unit (ALU) following , and can be tested in on nexys 4 board This is to be implement on : ISE Design Suite - Xilinx /* ALU Arithmetic and Logic Operations ---------------------------------------------------------------------- |ALU_Sel| ALU Operation ---------------------------------------------------------------------- | 0000 | ALU_Out = A + B; ---------------------------------------------------------------------- | 0001 | ALU_Out = A - B; ---------------------------------------------------------------------- | 0010 | ALU_Out = A * B; ---------------------------------------------------------------------- | 0011 | ALU_Out = A / B; ---------------------------------------------------------------------- |...
Analyze following logic expression representing a digital system, Z = (A+C)(A'+D')(B'+C'+D) Identify the 0-hazards and write...
Analyze following logic expression representing a digital system, Z = (A+C)(A'+D')(B'+C'+D) Identify the 0-hazards and write down the logic expression for the implementation of static free circuit. Note that you would be requiring three additional loops in K-map.
THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following...
THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following conditions: For night conditions, turn on white LED 1 For day conditions, turn off white LED 1 Code should check intervals every 5 seconds. NEED THE BELOW CODE TO FIT THE ABOVE REQUIREMENTS. const int lightSensor = 5; //light sensor variable float sensValue = 0; //variable to hold sensor readings const int button = 3; //pin for button reads const int LED1 = 5;...
Analyze the following Verilog code and write down its output as pictured in the code. module...
Analyze the following Verilog code and write down its output as pictured in the code. module blocking; reg [0:7] A, B; initial begin: init1 A = last decimal digit of your ID; #1 A = A + 1; // blocking procedural assignment B = A + 1; $display("Output 1: A= %b B= %b", A, B ); A = last decimal digit of your ID; #1 A <= A + 1; B <= A + 1; #1 $display ("Output 2: A=...
use modelsim write Verilog code for the following digital logic circuits and then simulate them by...
use modelsim write Verilog code for the following digital logic circuits and then simulate them by writing a testbench module for each of them , (a)The FSMs for the snail problem that is in the slides (a snail crawls over a tape that has 0 and 1 and smiles if it has detected the '10' bits using both Moore and Mealy FSM. Note that the pattern is '10' not '01' as in the slides. (b) A rock-paper-scissor game played by...
Write up to 10 lines to each code explain the logic used behind these code pls!!!!!...
Write up to 10 lines to each code explain the logic used behind these code pls!!!!! (10 lines for each please) 1. #include<iostream> using namespace std; int main() {        int id, reverse[20], count = 0, min = 0, max = 0;        cout << "\nStudent ID Number is \n";        cin >> id;        while (id != 0)        {              reverse[count] = id % 10;              if (count == 0)              {                     min = reverse[count];                     max...
Use python programming to write this code and provide a screen short for the code. 2....
Use python programming to write this code and provide a screen short for the code. 2. Write a function that takes one argument (a string) and returns a string consisting of the single character from that string with the largest value. Your function should contain a for loop. You can assume that the input to your function will always be a valid string consisting of at least one character. You can assume that the string will consist only of lower-case...
Programming. Write only code for the following. Do not write any comments. You can submit your...
Programming. Write only code for the following. Do not write any comments. You can submit your answer as .java file(s). #1. Design a Java JProduct class for a product which implements both cloneable and comparable interfaces The class should have the following private member variables: m_id: an integer that holds the product ID m_name: a string that holds the product name m_wholesaleprice: a double that holds the wholesale price m_retailers: a String array that holds all retailers who sell the...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the HTML file that references the JavaScript file. Use prompt to collect names of persons from the user. When the user enters ‘DONE’, your script should stop collecting more names. Then, it should ask the user to specify the following style properties: Border size? 2px, 5px, or 8px. Border Color? blue, red, green, and black. Border style? solid, dotted, dashed, and double. The HTML document...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the HTML file that references the JavaScript file. Use prompt to collect names of persons from the user. When the user enters ‘DONE’, your script should stop collecting more names. Then, it should ask the user to specify the following style properties: - Border size? 2px, 5px, or 8px. - Border Color? blue, red, green, and black. - Border style? solid, dotted, dashed, and double....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT