The following code is to calculate (base^pow)%mod
Can any one explain to me the following code which involves in declaring a variable to a function i want to know the value the function assigns to the variable and how it does it.
int tmp = mypow( base, pow >> 1, mod );
The whole code:
#include<stdio.h>
int mypow( int base, int pow, int mod )
{
if( pow == 0 ) return 1;
if( pow % 2 == 0 ){
int tmp = mypow( base, pow >> 1, mod );
printf("\n\n%d\n\n",tmp);
return tmp * tmp % mod;
}
else{
return base * mypow( base, pow - 1, mod ) % mod;
}
}
int main(){
printf("\n\n%d\n\n", mypow(25,20,22));
return 0;
}