Trace the following flowchart for the input values 3, 12, -2, 5, 15, 1, 1, 1 and complete the trace table. Also, write pre-post-conditions for this flowchart. start sum1(0 sum2-0 i+1 i+i+1 num F i≤4 sum1 +sum1 + num i+1 F i≤4 i+i+1 sum1=sum2 num T "no" "yes" sum2sum2+ num end

COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
1st Edition
ISBN:9780357392676
Author:FREUND, Steven
Publisher:FREUND, Steven
Chapter9: Formula Auditing, Data Validation, And Complex Problem Solving
Section: Chapter Questions
Problem 3EYK
icon
Related questions
Question

is the output correct.

The code was created from the flowchart in the image below

Code:

function problem2() {
 // this line will grab a string from the input box.
 var inputString = document.getElementById("a").value;
 // process the input string similar to flowchart2 function
 const values = inputString.split(',').map(Number);
 let result = values[0];
 let isNegative = false;

 for (let i = 1; i < values.length; i++) {
   if (isNegative) {
     result -= values[i];
   } else {
     result += values[i];
   }
   // Check if the current number is negative and update isNegative accordingly
   if (values[i] < 0) {
     isNegative = !isNegative;
   }
 }

 // Flip the sign of result only if isNegative is true at the end
 if (isNegative) {
   result = -result;
 }

 // write the result to the HTML page
 document.getElementById("output").innerHTML = result;
}

Trace the following flowchart for the input values 3, 12, -2, 5, 15, 1, 1, 1 and complete
the trace table. Also, write pre-post-conditions for this flowchart.
start
sum1(0
sum2-0
i+1
i+i+1
num
F
i≤4
sum1 +sum1 + num
i+1
F
i≤4
i+i+1
sum1=sum2
num
T
"no"
"yes"
sum2sum2+ num
end
Transcribed Image Text:Trace the following flowchart for the input values 3, 12, -2, 5, 15, 1, 1, 1 and complete the trace table. Also, write pre-post-conditions for this flowchart. start sum1(0 sum2-0 i+1 i+i+1 num F i≤4 sum1 +sum1 + num i+1 F i≤4 i+i+1 sum1=sum2 num T "no" "yes" sum2sum2+ num end
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage