when a developer commits a violation, or abuses an engineering principle!
Wednesday, 12 November 2008
Tuesday, 11 November 2008
Monday, 10 November 2008
Digit Factors-Recursion
bool DigitFactors::factors_helper(int digit)
{
int subDiv = digit;
if (subDiv == 1) return true;
for (int j = 2; j <= digit; ++j)
if ( (subDiv % j) == 0)
{
subDiv = subDiv/ j;
vec.push_back(j);
return factors_helper(subDiv);
}
return factors_helper(subDiv);
}
IsPrime?
public class IsPrime
{
public static bool isPrime(int x)
{
if (x <= 1)
return false;
for (int i = 2; i <= Convert.ToInt32(Math.Sqrt(x)); ++i)
if ((x % i) == 0)
return false;
return true;
}
}
Subscribe to:
Posts (Atom)