|
Mandelnuss wrote: and then manually split the OUTBUFF.recordData at the offsets calculated That is the general way to do it, even in unmanaged code (C++), so you are definitely on the right track.
|
|
|
|
|
Thanks for the help Richard!
|
|
|
|
|
if (value % 2 == 0) { x++; break; }
if (value % i == 0) { x++; break; }
Heres my problem with this. I am not understanding the logic and I need help with this. I would really appreciate your feedback.
Just as an example.
suppose i input value=5
i is going to check 1,3,5.
so 5%1= Remainder 0
5%3= Remainder 2
5%5= Remainder 0
Well since 5%3 has a remainder, doesnt this disqualify it? Obviously we all know that five is a prime number but what is the computer checking with the module??
Thank you guys so much and I hope you guys can teach me the logic behind this.
|
|
|
|
|
The modulo operator "%" in .NET C# returns the integral remainder of a number divided by (modulo) the divisor.
Any number where the modulo result is zero only when the divisor is the same as the dividend is prime (leaving out the obvious fact that every number is divisible by one).
A way that is perhaps useful to visualize this is:
int dividend = 5;
int divisor = 2;
int quotient = 5 / 2; // returns 2 since integer division in C# discards the remainder
int remainder = 5 % 2; // return 1
bool realityCheck = dividend == (quotient + remainder);
«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
modified 3-Jan-15 6:41am.
|
|
|
|
|
BillWoodruff wrote: int remainder = 5 % 2; // return 3 Really?
|
|
|
|
|
If we redesign the modulo to actually mean subtract, then yes.
|
|
|
|
|
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?
|
|
|
|