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 Trace the following flowchart for when input is 11 and complete the trace table. Also, write pre-post-conditions for this flowchart. start num prime true d2 prime true and d≤ num/2 prime = true num mod d = 0 "is not prime" num, "is prime" prime-false d+d+1 end

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 19SA
icon
Related questions
Question

Please help me is this code correct for the flowchart below

for the first code its supposed to display (e.g. 11 is prime or 11 is not prime). As well as the second code

function problem1() {
    // this line will grab a string from the input box.
    var inputString = document.getElementById("a").value;

    // process the input string similar to flowchart1 function
    const values = inputString.split(',').map(Number);
    let result = values[0];

    for (let i = 1; i < values.length; i++) {
        if (result < 0) {
            result = result * values[i];
        } else {
            result = result + values[i];
        }
    }

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


// Write more code below!
function problem2() {
      // this line will grab a string from the input box.
      var inputString = document.getElementById("b").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 (result < 0) {
              isNegative = true;
              result = -result;
          }

          if (isNegative) {
              result -= values[i];
          } else {
              result += values[i];
          }
      }

      if (isNegative) {
          result = -result;
      }

      // write the result to the HTML page
      document.getElementById("output2").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
Trace the following flowchart for when input is 11 and complete the trace table. Also,
write pre-post-conditions for this flowchart.
start
num
prime true
d2
prime true and
d≤ num/2
prime = true
num mod d = 0
"is not prime"
num, "is prime"
prime-false
d+d+1
end
Transcribed Image Text:Trace the following flowchart for when input is 11 and complete the trace table. Also, write pre-post-conditions for this flowchart. start num prime true d2 prime true and d≤ num/2 prime = true num mod d = 0 "is not prime" num, "is prime" prime-false d+d+1 end
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
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
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning