### Thread: Finding perfect squares between a range of input by user.

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
1
Rep Power
0

#### Finding perfect squares between a range of input by user.

Write a C program that finds the sum of the first two square
numbers between any given range of whole numbers..Example
of Output:
Range: 2 to 12
First two square numbers: 4 and 9
Sum of the squares: 13
first give a try and then if u face any problem then you should ask here.
3. With appropriate definitions, a j solution is
Code:
```   sum At (2 take isSquare Filter) At range 2 12
13```
Code:
```At=: @:
Filter=: (#~`)(`:6)
Under=: &.:
difference=: -/
equal=: =
integers=: i.
isSquare=: equal roundDown Under squareRoot
minimum=: <./
plus=: +
range=: minimum plus integers At difference
roundDown=: <.
squareRoot=: %:
sum=: +/
take=: {.```
4. and for the Schemers:
Code:
```(define (is-square? x) (= (* (sqrt x) (sqrt x)) x))
(define (get-square min-val max-val)
(cond
[(> min-val max-val) false]
[(is-square? min-val) min-val]
[else (get-square (+ min-val 1) max-val)]
))
... rest of code left for user to complete ...```
5. And get-square looks tail recursive. Please, is it so?
6. Yes sir, it is tail-recursive :)
7. Thank you! Clearly, 30 years of occasionally thinking about lisp has paid me a big dividend!

(I have read and understood this code.)