|
Oh, my bad. I plead insomnia. Corrected. thanks, Bill
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
I usually plead senility.
|
|
|
|
|
In your case, "senility" I seriously doubt ! How many moons have you ? I have 881.
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
Not sure whether you divide that by 12 or 13, but I'm a baby-boomer, born in '45.
|
|
|
|
|
Then I am at least 15~16 lunes ahead of you, biologically, which is a small comfort given how much your intellect is so far ahead of mine.
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
BillWoodruff wrote: how much your intellect is so far ahead of mine. Most unlikely. There are more things in heaven and I earth that I don't know, compared to the things that I do. And much of my 'intellect' is actually generated by Google.
|
|
|
|
|
value % whatever == 0 is checking for *no* remainder when divided by whatever.
Your algorithm should not be testing against 1 since every number is divisible by 1. There is a more optimized "standard" algorithm that increments by 6 on each iteration rather then 1. But that's about as efficient as you'll get. There isn't any efficient publicly known algorithm. Maybe the CIA spooks have one though LOL...
Being able to easily factor prime numbers would render all forms of cryptography useless.
|
|
|
|
|
int num1;
Console.WriteLine("Accept number:");
num1 = Convert.ToInt32(Console.ReadLine());
if (num1 == 0 || num1 == 1)
{
Console.WriteLine(num1 + " is not prime number");
Console.ReadLine();
}
else
{
for (int a = 2; a <= num1 / 2; a++)
{
if (num1 % a == 0)
{
Console.WriteLine(num1 + " is not prime number");
return;
}
}
Console.WriteLine(num1 + " is a prime number");
Console.ReadLine();
}
Heres my question.
looking at the if statement
if (num1%a==0)
num1 is not a prime. I am having a tough time understanding why that is.
|
|
|
|
|
Correct. If a number % anotherNumber == 0, (assuming anotherNumber is not 1 or the number itself), its not a prime.
6 % 3 = 0 means that 6 is divisible by 3, so 6 is not a prime.
|
|
|
|
|
Console.Write("Enter a Number : ");
int num;
num = Convert.ToInt32(Console.ReadLine());
int k;
k = 0;
for (int i = 1; i <= num; i++)
{
if (num % i == 0)
{
k++;
}
}
if (k == 2)
{
Console.WriteLine("Entered Number is a Prime Number and the Largest Factor is {0}",num);
}
else
{
Console.WriteLine("Not a Prime Number");
}
Console.ReadLine();
you seem to be very smart. so heres one last question for you. In this situation, what does the k stand for? why is it that if k=2 then the number that was entered is prime?
|
|
|
|
|
Its keeping track of how many factors it found (numbers that divide in evenly). If its exactly 2, then it has to be 1 and the number itself.
|
|
|
|
|
It's a good thing to vote for the answers of people, like SledgeHammer01, that spend their time answering your question, and who are willing to engage in discussion with you to assist you !
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
hi
how can i get number from a string like this :
<li ID='45'>
just using c#
thankyou
|
|
|
|
|
You can use a Regular Expression to retrieve this. The expression is as simple as \d
|
|
|
|
|
Great resource for RegEx's useful to convert from many formats to many numeric types: [^].
Try this:
private string getID = @"'\d+'";
private Regex rxGetID;
private char[] trimQuote = new[] {'\''};
private int? htmlToInt(string match)
{
rxGetID = new Regex(getID, RegexOptions.Compiled);
string result = rxGetID.Match(match).Value.Trim(trimQuote);
int intResult;
return (Int32.TryParse(result, out intResult))
? intResult
: (int?) null;
}
private void Test()
{
rxGetID = new Regex(getID,RegexOptions.Compiled);
int? result = htmlToInt("<li> ID='45'");
if (result != null)
{
}
else
{
}
}
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
C# - Visual Studio 2012
I've seen libraries for custom YouTube applications on the Internet.
Can I write my own YouTube program that will run on my XBox 360?
Thanks
|
|
|
|
|
Yes, if you know how to write programs for the XBox, and you are allowed to install your own software on the device.
|
|
|
|
|
|
Thank you! Great link.
Do you know if we are allowed to sell anything we create for XBox?
|
|
|
|
|
The Dreamspark link says:
"We also provide you with a developer dashboard so you can manage all aspects of how your app or game appears in either marketplace, monitor downloads, and track how much money you’ve earned." So I'd say that was a "yes"
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Dreamspark wants me to be a student to download and I am not a student.
|
|
|
|
|
But if you can sell stuff via the Dreamspark scheme, you can sell it via other schemes as well - just MS may change the percentage they take from each sale.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Start here: [^].
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
|
I'm getting this error message on my laptop (win7 64bit/visual studio 2012 express), but not my desktop (win7 64bit/visual studio 2012 pro), code is unchanged.
This is happening when my code runs through Quote: var versionPtr = GetPropellerVersion();
Which is a dll import call via the code below, so it has something to do with the unmanaged code, but I'm a bit confused as to why? I believe the dll is 32 bit, so I've set the project to force x86, but I'm unsure as to what else could cause this? The project is set to 'copy always' the dll as well. I've also tried it in debug and release mode, same conflicting results.
Does anyone have any ideas? Thanks for reading.
Quote: [DllImport("Propellent.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetPropellerVersion();
Quote: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at program.GetPropellerVersion()
at program.btnDetectPort_Click(Object sender, EventArgs e) in program\Form1.cs:line 1750
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NatiThe program '[48096] program.exe: Managed (v2.0.50727)' has exited with code -1073741819 (0xc0000005) 'Access violation'.
veWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at program.Program.Main() in program\Program.cs:line 19
private void btnDetectPort_Click(object sender, EventArgs e)
{
cbxSerialPort.Items.Clear();
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
cbxSerialPort.Items.Add(port);
cbxSerialPort.SelectedIndex = 0;
serialPort1.PortName = port;
serialPort1.BaudRate = 115200;
serialPort1.Encoding = Encoding.ASCII;
try
{
serialPort1.Open();
this.Invoke(new EventHandler(delegate
{
serialPort1.Close();
}));
}
catch (Exception)
{
}
}
var versionPtr = GetPropellerVersion();
string version = Marshal.PtrToStringAnsi(versionPtr);
int delimiter = version.IndexOf(':');
if (delimiter > -1)
{
string comPort = version.Remove(delimiter - 1);
string firmWare = version.Remove(0, delimiter + 2);
tbxPropPortFound.Text = comPort;
int comPortIndex = cbxSerialPort.FindString(comPort);
cbxSerialPort.SelectedIndex = comPortIndex;
}
}
|
|
|
|