Posted: Thu Jan 26, 2012 9:50 pm Post subject: Is Perfect TURING
What is it you are trying to achieve?
I am trying to make a program that displays a message if a positive integer is a perfect square or not
What is the problem you are having?
my program almost works like if u input 6, it will display that has a perfect square but its not always that accurate with other numbers and i think i just did trial and erro
Turing:
procedure IsPerfect
%Declare the variables var number :int var sum :int %Ask the user what the number is put"What is the number?" get number
for i :1.. number - 1 if number mod i =0then
sum := i + i
endif endfor %Display if it is a perfect or not a perfect number if sum = number then put"The number is a perfect number" else put"The number is not a perfect number" endif
%End the procedure end IsPerfect
IsPerfect
Please specify what version of Turing you are using
<Answer Here>
Sponsor Sponsor
mirhagk
Posted: Thu Jan 26, 2012 9:55 pm Post subject: RE:Is Perfect TURING
perfect squares is something different than this. A perfect square is something that's square root is a whole number.
I'm assuming this is a number that has the same number of factors as it's value itself? Then this program should work fine.
Tony
Posted: Thu Jan 26, 2012 9:55 pm Post subject: Re: Is Perfect TURING
nasur27 @ Thu Jan 26, 2012 9:50 pm wrote:
like if u input 6, it will display that has a perfect square
What integer, when multiplied by itself, will result in 6?
Posted: Fri Jan 27, 2012 1:39 am Post subject: RE:Is Perfect TURING
Well what was the question being asked, by perfect number do you mean perfect squares?
Dreadnought
Posted: Fri Jan 27, 2012 1:55 am Post subject: Re: Is Perfect TURING
Just looking at the code, I'd say he's actually talking about perfect numbers, (6 is a perfect number). These are numbers which are equal to the sum of all their factors (not including themselves).
ex : 6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
(There are tow more less than 10000)
The problem I seem is that you haven't set an initial value for sum, and that you let sum be equal to i+i instead of incrementing the value of sum by i.
This works for 6 since, the largest factor less than 6 is 3 and 3+3 =6, But you will notice that this will also work for any multiple of two.