Lesson goal: $\sqrt{n}-\sqrt{n-1}<0.01$

Previous: Solving equations | Home | Next: Introduction

Use a while-loop to find the smallest positive integer $n$, such that $\sqrt{n}-\sqrt{n-1}<0.01$.

Remember that $\sqrt{something}$ in Lua is math.sqrt(something).

What is your answer? a) 2499 b) 2500 c) 2501 or d) 10,000 e) there is no such integer. (From Artino, 1978, #18.)

Now you try. Fix the while loop to stop when d becomes less than 0.01, and fix the d= line to compute $\sqrt{n}-\sqrt{n-1}<0.01$.

Type your code here:

See your results here:

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.