•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 427,494 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,464 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 1732 | Replies: 5
![]() |
Hey, this hailstone numbers thing is pretty cool. Apparently there are some rewards out there for anyone who can solve it (whatever that means.) I embarrased myself the other day when I resserected a very old topic in the C++ C forum from two years ago asking a question about this. (Sorry about that mods!) Anyway, I don't code very well in C++ though I tried to do it. I just coded it in C#. So here it is. Sorry about the delay, I had finals.
c Syntax (Toggle Plain Text)
using System; using System.Text; namespace ConsoleApplication1 { class Program { // Helpful url: [url]http://en.wikipedia.org/wiki/Hailstone_numbers[/url] static void Main(string[] args) { int first; System.Console.WriteLine("Enter the integer you would like to run the function on: "); first = int.Parse(System.Console.ReadLine()); while (first != 1) { System.Console.Write(first + " "); first = f(first); } System.Console.WriteLine(first); System.Console.WriteLine("Press enter to continue."); ConsoleKeyInfo c = System.Console.ReadKey(); while (c.Key != ConsoleKey.Enter) { c = System.Console.ReadKey(); } } private static int f(int first) { if (first % 2 == 0)//test to see if even { return first /= 2; } else { return first = 3 * first + 1;//is odd } } } }
Hi Godfear, don't worry about that, we all learn from our mistakes.
However, remember daniweb's homework policy. We don't do ppl's homework, especially if the poster has shown no sign of effort.
However, remember daniweb's homework policy. We don't do ppl's homework, especially if the poster has shown no sign of effort.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
Other Threads in the C# Forum
- Previous Thread: calculate with metrics
- Next Thread: having problem while creating factorial




Linear Mode