Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Necklace Problem In Visual Basic
redskins
post Dec 6 2007, 08:07 PM
Post #1


Newbie [ Level 1 ]
Group Icon

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
Go to the top of the page
 
+Quote Post
turbopowerdmaxst...
post Dec 7 2007, 09:00 AM
Post #2


Premium Member
Group Icon

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
Go to the top of the page
 
+Quote Post
faulty.lee
post Dec 10 2007, 03:24 PM
Post #3


Premium Member
Group Icon

Group: [HOSTED]
Posts: 495
Joined: 5-November 06
Member No.: 17,016



QUOTE(redskins @ Dec 7 2007, 04:07 AM) *
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.
Go to the top of the page
 
+Quote Post
tansqrx
post Dec 10 2007, 05:31 PM
Post #4


Super Member
Group Icon

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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. [visual Basic] How To Confirm A Array Is Null(6)
  2. Visual Basic Help(7)
  3. Visual Basic: Replace Explained!(4)
  4. Visual Basic: Unload Your Application Correctly!(1)
  5. Visual Basic: Change Your Start Button Text! (XP)(16)
  6. Visual Basic: Random Strings!(10)
  7. Visual Basic 6 + Crystal Reports 9(6)
  8. Visual Basic Names(11)
  9. New Features In Visual Studio 2005 Windows Forms(1)
  10. Visual Basic.NET Help Needed.(7)
  11. Is There A Free IDE For VB.NET Programming?(4)
  12. Visual Basic Express Tutorials(5)
  13. [help] Visual Studio .net 2005 Questions(8)
  14. Installed Internet Explorer 7?, Visual Basic Now Broken?(3)
  15. Visual Basic Projects: Scoreboard(0)
  1. Delete A Registry Subkey And Key(8)


 



- Lo-Fi Version Time is now: 11th October 2008 - 06:15 PM