Search code examples
cfunctioncompiler-errorsinversemodular

conflicting types for my function "inverse", which is designed to return long long type


I try to figure out what I did wrong here, basically the function is for calculating the module inverse number to a-1 mod m. but program is getting errors.

can somebody point out what is causing the errors?

//calculating the inverse of the public key, for getting private key d. long     
long long inverse(long long a, long long m) 
{ 
   long long p = a, q = m, t; 
   //Euclidean algorithm 
   long long x = 0, y = 1, z = (long long)q/p; 

   //start recursion 
   while(p != 1 && q != 1) 
   {
       t = p; 
       p = q % p; 
       q = t; 
       t = y; 
       y = x - y * z; 
       x = t; 
       z = (long long)q/p; 
   } 

   y = (long long)y % m; 
   if(y < 0) 
   { 
      y += m; 
   } 

   //return inverse number; 
   return y; 
}

Solution

  • You declared a function prototype that doesn't match the function definition, example of how you can do that, put at the top of the file or in a header file the following

    int inverse(int a, int n);
    

    and then your definition is

    long long inverse(long long a, long long n)
    {
    }