Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I haven't worked with Pascal so far, and my problem is understanding the recursive aspects that prm assignment operators and how the final (correct) value is derived. Would someone please explain that line for me.

Program test(output);

FUNCTION prm(az:integer) : real;
begin
    if az = 1 then
        prm := sqrt(12)
    else
        prm := sqrt(12*prm(az-1));
end;

begin
    writeln(prm(30):0:2);
end.
share|improve this question

closed as unclear what you're asking by GlenH7, gnat, Kilian Foth, Giorgio, Bart van Ingen Schenau Oct 28 '13 at 12:10

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
What don't you understand about it? Is this homework? If so, have you asked an instructor? You may also find freepascal.org/docs-html/ref/ref.html of use. –  MichaelT Oct 27 '13 at 18:40
    
It's not homework. It's my question and I understand most part of it. I haven't worked with Pascal so far, and my problem is that prm= has become some radicals inside each order. Please explain that line for me. Moreover, guys, what's your problem with my question? It's a beginner's question, after all. –  mghaffari Oct 27 '13 at 19:24
6  
The phrasing of your question is a bit on the demanding side without specifying what the actual problem that you are having understanding. We routinely have difficulty with students asking (and sometimes demanding) us to do their homework for them. The problem here is that you don't understand recursion in programming, not that you need someone to trace the code for you. Beginner questions are ok, but it helps to see some amount of initiative on the part of the person asking the question. You may wish to read whathaveyoutried.com to get a better view of this endemic problem. –  MichaelT Oct 27 '13 at 19:45
add comment

1 Answer 1

up vote 3 down vote accepted

This is a recursive function in pascal. The 'return' value that C like language people are familiar with is instead done by assigning a value to the psuedo-value of the function name itself.

When passed a parameter of 1, it returns the square root of 12.

enter image description here

When passed a parameter of 2, it returns the square root of 12 times the square root of 12 (the value it was passed with 1).

enter image description here

When passed a parameter of 3, it returns the square root of 12 times the value when it was passed with 2.

enter image description here

And so on...

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.