I'll recommend you to read these:
1
2
3
Type: Posts; User: Mr.777
I'll recommend you to read these:
1
2
3
Why don't you try making it iterative?
Man!!! Try writing a factorial program and give it a value of 100 and run it, you'll come to know the result...
And what's your RAM size by the way? Of course when you will input too large values, your RAM will definitely let it's stack overflow as you are using recursion. If you still want to do this,...
else if (2%p == 1) // if odd
{
r= modPower(x, ((int)(p/2)), m);
r *= r;
}
else // if even
{
r = x * modPower(x, p-1, m);
1. Hopefully some type casting issues.
2. Did you declare ret somewhere? I mean it is declared and initialized in your whole program?
3. As you are new to Java, may be you are missing main()...