Pseudo code Standard

Data structures & algorithms topics
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Pseudo code Standard

Post by Neo » Wed Mar 24, 2010 2:26 pm

We must always encourage people to write something their own first. Doesn't matter it is incorrect. Here is a simple pseudo code. See whether you can improve it. There is a little advance algorithm technique called recursion. You might try to use here as well.

Code: Select all

number  = raw_input("Please enter an integer: ")
itemCount = 0
maxNum = number

IF (number != 0) THEN  // != is used to denote "not equals"

    WHILE (number != 4)     // && is used to conditional AND operator

        print (number + ", ")

        IF (number & 1) THEN   // odd number (Note & is used to bitwise AND operation)
            number = number * 3 + 1
        ELSE
            number = number / 2
        END IF

        IF (maxNum < number) THEN  // Set max number
            maxNum = number
        END IF

        itemCount = itemCount + 1
    ENDWHILE

    println (number + ", 2, 1")    // println is used to print on a new line
    println ("Total items " + itemCount)
    println ("Largest Number in Sequence " + maxNum)
ELSE
    println ("Invalid number entry")
END IF
See whether this helps!
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: Pseudo code Standard

Post by Face » Wed Mar 24, 2010 4:56 pm

thanks BUDDY.....!!!!!!

for every thing done...
Post Reply

Return to “Data Structures & Algorithms”