Finding square roots
Moderator:Moderators
Hey. I need the best way to find square roots WITHOUT a calculator.
How would finding the square root help you find out if a number is prime or not?
You could just have the program divide the number in question by all the whole numbers before it (except itself and 1), and if it doesn't get a whole number as the answer for any of them, then its prime.
Theres probably an easier/faster way, but thats my only idea.
You could just have the program divide the number in question by all the whole numbers before it (except itself and 1), and if it doesn't get a whole number as the answer for any of them, then its prime.
Theres probably an easier/faster way, but thats my only idea.
How large? If they're less than 1,000, it'd probably be a good idea to just print out a list of the prime numbers up to 1,000. If you have a graphing calculator, I'm sure you'll be able to find a program that could tell you if a number is prime (check ticalc.org if its a TI).ghosstt wrote:The idea you have is what we did in school, though very inefficient for larger numbers..
Code: Select all
int PrimeTest(int x)
{
x = abs(x);
if(!x)
{
return 1;
}
for(int i = 2; i <= sqrt(x); i++)
{
if(x % i == 0)
{
return 0;
}
}
return 1;
}
wtf is that.. C++?
im using VB.net btw
im using VB.net btw
Last edited by ghosstt on Fri Oct 19, 2007 4:38 pm, edited 1 time in total.
a variable storing the number of loops the loop has gone thru.
Come on, calling that i is like, the first thing you learn when coding.
edit:
does VB even have for?
Come on, calling that i is like, the first thing you learn when coding.
edit:
does VB even have for?
Last edited by Kyo on Fri Oct 19, 2007 4:42 pm, edited 2 times in total.