redskins 0 Report post Posted December 6, 2007 I was wondering if anyone could write code for this program. Its the usual Necklace Problem I'll give you the problem.A Necklace is a collection of numbers that begins with two single digit integers, the next number is obtained by adding the first two digits together and saving only the ones digit. This process is repeated until the 'necklace' closes by returning to the original two numbers. I think it is a Do While Loop but i am not sure. Thankyou Share this post Link to post Share on other sites
turbopowerdmaxsteel 0 Report post Posted December 7, 2007 You are the second person to have reached here for this problem. You can find the VB .NET and C# codes for this problem at http://forums.xisto.com/no_longer_exists/ Its fairly easy to do. I'll jot down the algorithm for the Function that returns the output as a string. Function Name: Necklace Inputs: OrigFirstNum (integer) and OrigSecNum (integer) Return: String Step 1: Set FirstNum = OrigFirstNum and SecondNum = OrigSecNum Step 2: Concatenate FirstNum and SecondNum and store the result in Output Step 3: Repeat Steps 4 - 7 until FirstNum = OrigFirstNum and SecondNum = OrigSecondNum Step 4: Set Result = FirstNum + SecondNum Step 5: Set FirstNum = SecondNum Step 6: Find the last digit of Result and store it in SecondNum Step 7: Concatenate SecondNum to Output Step 8: Return Output To find the last digit of a number use the following algorithm:- Function Name: GetLastDigit Input: Num (integer) Return: Integer Step 1: Divide Num by 10 and return the remainder Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted December 10, 2007 I was wondering if anyone could write code for this program. Its the usual Necklace Problem I'll give you the problem.A Necklace is a collection of numbers that begins with two single digit integers, the next number is obtained by adding the first two digits together and saving only the ones digit. This process is repeated until the 'necklace' closes by returning to the original two numbers. I think it is a Do While Loop but i am not sure. ThankyouYou'll need a do loop, as shown in the link posted by turbopowerdmaxsteel. A While loop will need a variable, such as a boolean to be checked every loop. You'll have to exit the loop by changing the variable to false. As for Do loop, you just need to call Exit Do when the condition match what you want. Share this post Link to post Share on other sites
tansqrx 0 Report post Posted December 10, 2007 Sounds like a homework problem to me. Not that I have never been guilty of doing “research” on the Internet, but I have always found the best way to retain knowledge is to work the problem out on your own. If you develop the mythology for problem solving then you will be able to apply that to many other areas of your life.Steps off soapbox. Share this post Link to post Share on other sites