While I'm using gmp.h header file. I need a function which takes inputs of type mpz_t and return mpz_t type too. I'm very beginner of using gmp.h So, Here is snaps follows of my approached code...
mpz_t sum_upto(mpz_t max)  
{    
    mpz_t sum;  
    mpz_init(sum);    
    mpz_init(result);  
    for(int i=0;i<=max-1;i++)    
        mpz_add_ui(sum,sum,pow(2,i));   
    return sum;   
}
but it will show error:
The convention for functions using GMP can be found in the manual. Essentially, you must follow the same conventions that GMP itself does - the function must have a void return type, and you must provide a value into which to put the result as a parameter.
Here is the example given:
 void foo (mpz_t result, const mpz_t param, unsigned long n)
 {
   unsigned long  i;
   mpz_mul_ui (result, param, n);
   for (i = 1; i < n; i++)
     mpz_add_ui (result, result, i*7);
 }
 int main (void)
 {
   mpz_t  r, n;
   mpz_init (r);
   mpz_init_set_str (n, "123456", 0);
   foo (r, n, 20L);
   gmp_printf ("%Zd\n", r);
   return 0;
 }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With