Create a trace table to determine the values of the variables in each step of the following program when a value of 3 is entered.

PHP

<?php
  $a = trim(fgets(STDIN));
    
  $b = $a + 10;
  $a = $b * ($a - 3);
  $c = 3 * $b / 6;
  $d = $c * $c;
  $d--;
        
  echo $d;    
?>
Solution

For the input value of 3, the trace table looks like this.

StepStatementNotes$a$b$c$d
1$a = trim(fgets(STDIN))User enters value 33???
2$b = a + 10 313??
3$a = $b * ($a - 3) 013??
4$c = 3 * $b / 6 0136.5?
5$d = $c * $c 0136.542.25
6$d-- 0136.541.25
7echo $dThe value 41.25 is displayed

Java

public static void main(String[] args) throws java.io.IOException {
  java.io.BufferedReader cin = new java.io.
          BufferedReader(new java.io.InputStreamReader(System.in));
  double a, b, c, d;

  a = Double.parseDouble(cin.readLine());
    
  b = a + 10;
  a = b * (a - 3);
  c = 3 * b / 6;
  d = c * c;
  d--;
        
  System.out.println(d);    
}
Solution

For the input value of 3, the trace table looks like this.

StepStatementNotesabcd
1a = Double.parseDouble(cin.readLine())User enters value 33???
2b = a + 10 313??
3a = b * (a - 3) 013??
4c = 3 * b / 6 0136.5?
5d = c * c 0136.542.25
6d-- 0136.541.25
7System.out.println(d)The value 41.25 is displayed

C++

#include <iostream>
using namespace std;
int main() {
  double a, b, c, d;

  cin >> a;
    
  b = a + 10;
  a = b * (a - 3);
  c = 3 * b / 6;
  d = c * c;
  d--;
        
  cout << d;    
  return 0;
}
Solution

For the input value of 3, the trace table looks like this.

StepStatementNotesabcd
1cin >> aUser enters value 33???
2b = a + 10 313??
3a = b * (a - 3) 013??
4c = 3 * b / 6 0136.5?
5d = c * c 0136.542.25
6d-- 0136.541.25
7cout << dThe value 41.25 is displayed

C#

static void Main() {
  double a, b, c, d;

  a = Double.Parse(Console.ReadLine());
    
  b = a + 10;
  a = b * (a - 3);
  c = 3 * b / 6;
  d = c * c;
  d--;
        
  Console.Write(d);    
  Console.ReadKey();
}
Solution

For the input value of 3, the trace table looks like this.

StepStatementNotesabcd
1a = Double.Parse(Console.ReadLine())User enters value 33???
2b = a + 10 313??
3a = b * (a - 3) 013??
4c = 3 * b / 6 0136.5?
5d = c * c 0136.542.25
6d-- 0136.541.25
7Console.Write(d)The value 41.25 is displayed

Visual Basic

Sub Main()
  Dim a, b, c, d As Double

  a = Console.ReadLine()

  b = a + 10
  a = b * (a - 3)
  c = 3 * b / 6
  d = c * c
  d -= 1

  Console.Write(d)

  Console.ReadKey()
End Sub

Solution

For the input value of 3, the trace table looks like this.

StepStatementNotesabcd
1a = Console.ReadLine()User enters value 33???
2b = a + 10 313??
3a = b * (a - 3) 013??
4c = 3 * b / 6 0136.5?
5d = c * c 0136.542.25
6d -= 1 0136.541.25
7Console.Write(d)The value 41.25 is displayed

Python

a = float(input())

b = a + 10
a = b * (a - 3)
c = 3 * b / 6
d = c * c
d -= 1

print(d)
Solution

For the input value of 3, the trace table looks like this.

StepStatementNotesabcd
1a = float(input())User enters value 33???
2b = a + 10 313??
3a = b * (a - 3) 013??
4c = 3 * b / 6 0136.5?
5d = c * c 0136.542.25
6d -= 1 0136.541.25
7print(d)The value 41.25 is displayed