Is Number Odd?


Closed Thread
Results 1 to 30 of 30

Thread: Is Number Odd?

Hybrid View

  1. #1
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Here's another approach:

    Code:
    TestNumber as word
    TestVal as word
    
    If TestNumber = 0 then Zero
    TestVal = 2
    Test:
    	If TestNumber = TestVal Then
    		LCDOUT "Even"
    		EndProgram
    	Else
    		If TestNumber = TestVal - 1 then
    			LCDOUT "Odd"
    			EndProgram
    		Else
    			TestVal = TestVal + 2
    			Test
    		EndiF
    	Endif
    
    Zero:
    	LCDOUT "Zero"
    	EndProgram
    
    EndProgram:
    end

  2. #2
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by SteveB View Post
    Here's another approach:

    Code:
    TestNumber as word
    TestVal as word
    
    If TestNumber = 0 then Zero
    TestVal = 2
    Test:
    	If TestNumber = TestVal Then
    		LCDOUT "Even"
    		EndProgram
    	Else
    		If TestNumber = TestVal - 1 then
    			LCDOUT "Odd"
    			EndProgram
    		Else
    			TestVal = TestVal + 2
    			Test
    		EndiF
    	Endif
    
    Zero:
    	LCDOUT "Zero"
    	EndProgram
    
    EndProgram:
    end
    Excellent! That's called a recursive method.

    Trent Jackson

Similar Threads

  1. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 17:03
  2. dec number to show on lcd (maths)
    By savnik in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th August 2007, 19:18
  3. Working with the random number generator
    By kwelna in forum mel PIC BASIC
    Replies: 9
    Last Post: - 16th January 2007, 17:50
  4. Random number results
    By bartman in forum mel PIC BASIC
    Replies: 3
    Last Post: - 9th March 2005, 17:39
  5. more random number questions
    By bartman in forum mel PIC BASIC
    Replies: 1
    Last Post: - 14th November 2004, 17:55

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts