English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

The following procedure was designed to compute the largest integer whose squre is no greater than N, where N is assumed to be a positive number. (if N is 5, then the procedure should report the vale 2.) Find and correct the error.

procedure squareroot (N)
X ← 0;
while (X(squared) < (or equal to) N) do
(X ← X + 1);
report the value of X

2007-11-08 23:02:52 · 6 answers · asked by Cap10kirk 3 in Computers & Internet Programming & Design

6 answers

I won't give you the answer outright, but I will tell you to look at the conditional on your loop (the while).

Have fun.

2007-11-08 23:31:12 · answer #1 · answered by monstertoe 2 · 0 0

To me your while loop will exits too late. So if N=5 then X will go to 2, go through the condition, assign X=X+1 and only then will fail the condition being equal 3. And 3 is returned.

2007-11-08 23:38:22 · answer #2 · answered by ? 2 · 0 0

If you sit down and step through the instructions until the end of the loop you will find the answer.
It will not take you long.
Start as suggested with N set to 5.
Now you continue.

Remember. The answer you should get is 2.

2007-11-08 23:25:37 · answer #3 · answered by AnalProgrammer 7 · 0 0

Heigh ho ! Who is there ?
No one but me, my dear.
Please come say, How do ?
The things I'll give to you.
By stroke as gentle as a feather
I'll catch a rainbow from the sky
And tie the ends together.


Heigh ho ! I am here
Am I not young and fair ?
Please come say, How do ?
The things I'll show to you.
Would you have a wond'rous sight
The midday sun at midnight ?
Fair maid, white and red,
Comb you smooth and stroke your head
How a maid can milk a bull !
And every stroke a bucketful.

2007-11-08 23:17:12 · answer #4 · answered by bottle babe 4 · 0 0

I would suggest you get off of the internet and study.

2007-11-08 23:05:53 · answer #5 · answered by holeeycow 5 · 0 0

Should've done it sooner, then, shouldn't you, you lazy little sod.

2007-11-08 23:06:07 · answer #6 · answered by Kango Man 5 · 1 0

fedest.com, questions and answers