what is wrong with this code?
Modular exponentiation
Hi @mehak61
In your code in modExp function you are taking y as long so you have to set the return type of this function also as long. And in the else case you have to do :
y=modExp(a,b-1,c);
y=(y*a)%c;
You are passing modExp(a,b-1,c) as second argument, instead of this you only have to pass b-1. And also while computing y you are using y=a%c, here you have to do y=(ya)%c. And first you have to make call function then use this y value to compute y=(ya)%c;
Here is your corrected code . :