Author |
Message |
bgmrk
![](http://www.lemmongrove.com/img/novels-vampire-film-logo.jpg)
|
Posted: Sun Jan 29, 2006 4:44 pm Post subject: real to int? |
|
|
i'm trying to make a program that will recognize whether a number is a perfect square (8 is a perfect square of 64) or not i'm a little confused...i'm trying to use the round command to make it aout 100 times easier but its not going to well
this is what i have: Code:
code: |
var x, y : real
for i : 40..100
y := i**0.5
if y*y = i then
put i
end if
end for
|
this gives all the numbers that aren't perfect squares
this is what i want
code: |
var x, y : real
for i : 40..100
y := i**0.5
round (y)
if y*y = i then
put i
end if
end for
|
how do i fix this error so it actualy works |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Sun Jan 29, 2006 4:49 pm Post subject: Re: real to int? |
|
|
Please indent.
bgmrk wrote:
code: |
var x, y : real
for i : 40..100
y := i**0.5
% Takes sqrt.
if y*y = i then
% checks if square is i
put i
end if
end for
|
That part makes no sense. Basically, it's:
math wrote:
(sqrt(x))^2 = x
Ergo, all values will return.
What you'll want to do (if I understand your intent correctly) is check if the sqrt() of a given number is a whole number. If it is, then woo-hoo, it's a perfect square.
There are probably more mathematically correct ways of doing it, of course. |
|
|
|
|
![](images/spacer.gif) |
bgmrk
![](http://www.lemmongrove.com/img/novels-vampire-film-logo.jpg)
|
Posted: Sun Jan 29, 2006 4:53 pm Post subject: (No subject) |
|
|
thanx for the quick reply nd sry for not indenting
where would i put that line because i am still ver confused |
|
|
|
|
![](images/spacer.gif) |
bgmrk
![](http://www.lemmongrove.com/img/novels-vampire-film-logo.jpg)
|
Posted: Sun Jan 29, 2006 5:08 pm Post subject: (No subject) |
|
|
ok ok i got it...thanx..so much this was my last one to do..u r a god sent:)![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) ![Smile Smile](images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
redrenagade
|
Posted: Thu Feb 02, 2006 5:04 pm Post subject: (No subject) |
|
|
Just what do you plan to use that for anyway? Just curious. |
|
|
|
|
![](images/spacer.gif) |
bgmrk
![](http://www.lemmongrove.com/img/novels-vampire-film-logo.jpg)
|
Posted: Thu Feb 02, 2006 5:10 pm Post subject: (No subject) |
|
|
it's for school...but i figured it out...thanx |
|
|
|
|
![](images/spacer.gif) |
|