powers and factorials...
{
if(num2In > 1)
return num1In*power(num1In, num2In-1);
else if(num2In < 0)
return 1.0/power(num1In, -num2In);
else
if (num2In == 0)
return (1);
else
return (num1In);
}
public static int factorial(int n)
{
return _factorial(n, 1);
}
private static int _factorial(int n, int result)
{
if (n <= 0)
{
return result;
}
else
{
return _factorial(n - 1, n * result);
}
}
i'll probably be back here next semester with possibly something slightly more taxing for you. ;) thanks much again.
---
this is most definitley painfully simple for the most of you i expect but i just can't seem to get my head around it...
i need to write 2 methods, one to calculate powers (2 numbers given) and the other to calculate factorials (1 number given)
{
return (num1In);
}
public static double factorial (double num1In)
{
return (num1In);
//The factorial of 0, written 0!, is 1. The factorial of a positive whole number N, written N!, is N multiplied by the factorial of N - 1.
}
i'm really not expecting anyone to code this for me or anything. just a little help with the design, i think the factorial one needs to use recursion? and the powers a loop in a loop?
sometimes i feel i'm really on the wrong degree. :S
