recategorized by
6,934 views
13 votes
13 votes

What is the value of $X$ printed by the following program?

program COMPUTE (input, output);
var X:integer;
procedure FIND (X:real);
    begin
        X:=sqrt(X);
    end;
begin
    X:=2
    FIND(X);
    writeln(X);
end.
  1. $2$
  2. $\sqrt{2}$
  3. Run time error
  4. None of the above
recategorized by

6 Answers

0 votes
0 votes
It goes into an infinite loop as the 2nd prog. goes on calling the 1st prog. And it never reaches the writeline ..so itdoesnt print anything
0 votes
0 votes

n the main program, the variable X is assigned the value 2, and then the procedure FIND is called with X as an argument. Inside the procedure, the square root of X is calculated.

The writeln(X) statement outside the procedure will print the value of X after the procedure call. Since X was assigned the value 2 before calling the procedure, and the procedure only calculates the square root without modifying the original value of X in the main program, the output will be:2

Answer:

Related questions

44 votes
44 votes
1 answer
2
15 votes
15 votes
3 answers
3
Kathleen asked Oct 8, 2014
4,564 views
What are $x$ and $y$ in the following macro definition?macro Add x, y Load y Mul x Store y end macroVariablesIdentifiersActual parametersFormal parameters
5 votes
5 votes
1 answer
4