Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Is Perfect TURING
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nasur27




PostPosted: 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 = 0 then
            sum := i + i
        end if
    end for
    %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"
    end if


    %End the procedure
end IsPerfect
IsPerfect




Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
mirhagk




PostPosted: 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




PostPosted: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
mirhagk




PostPosted: 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




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: