|
|
|
|
![]() ![]() |
Dec 6 2007, 08:07 PM
Post
#1
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 1 Joined: 6-December 07 Member No.: 26,706 |
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 |
|
|
|
Dec 7 2007, 09:00 AM
Post
#2
|
|
|
Premium Member Group: [HOSTED] Posts: 392 Joined: 16-February 06 From: Kolkata, India Member No.: 11,322 |
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://maxotek.net/blog/?p=51
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 |
|
|
|
Dec 10 2007, 03:24 PM
Post
#3
|
|
|
Premium Member Group: [HOSTED] Posts: 495 Joined: 5-November 06 Member No.: 17,016 |
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 You'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. |
|
|
|
Dec 10 2007, 05:31 PM
Post
#4
|
|
|
Super Member Group: [HOSTED] Posts: 533 Joined: 25-April 05 Member No.: 4,374 |
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. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 11th October 2008 - 06:15 PM |