I'm new to C#. And I would like to program something like, displaying the prime numbers in a listbox if user will input any integer in the textbox. (that means, if they write 10, it will display the prime numbers from 0-10, or 20 from 0-20, etc).
What should I consider first, before I do the programming?
I know there are many examples in the internet, but first I would like to know what will I need?
Thanks for the tip;-)
===
Thanks guys. So you're suggesting that it's better to do it first in the Console application?
I did an example of "For Loop" using Console Application a very simple one, but then when I tried to do it in the Windows Form Application, I'm not sure how to implement it.
I'm afraid that if I keep doing examples in the Console, then I'll have difficulty to do it in Windows Form Apps.
What do you think?
======
Hello again,
I need some feedback with my code:
Console.WriteLine("Please enter your integer: ");
long yourInteger;
yourInteger = Int32.Parse(Console.ReadLine());
//displaying the first prime number and comparing it to the given integer
for (long i = 2; i <= yourInteger; i = i + 1)
{
//Controls i if its prime number or not
if ((i % 2 != 0) || (i == 2))
{
Console.Write("{0} ", i);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…