I'm currently learning about GMP in a course about scientific programming. I need to print the table of 23^45. This is a unusual big number, so I need to work with GMP.
I have to problem with constructing a loop from 1 to 10. The trouble lies in assingning 23^45 to a variable. I searched for it online, but I couldn't find anything simillar.
So far I know that first the mpz_t variables need to be defined. Then memory needs to be allocated for the variable. The next step is to assign the values to the variables.
I already read this documentation: https://tspiteri.gitlab.io/gmp-mpfr-sys/gmp/Integer-Functions.html
Therefore I know that I can assign a value with mpz_set_str(variable, "str", base)
or with mpz_set_d(variable, value to assign).
So far I have:
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include <math.h>
int main(void)
{
mpz_t a,b;
// allocate memory for the variables
mpz_init(a);
mpz_init(b);
I want to achieve something like this:
// assign values
mpz_set_d(a,pow(23,45));
mpz_set_str(b,"pow(23,45)",10)
From here I'm confused and I haven't been able to find an example. It would be great if anybody could help me or direct me to a simmilar thread.
Ter
UPDATE:
I now have this piece of code:
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include <math.h>
int main(void)
{
mpz_t a,b,c,d;
mpz_init(c);
mpz_init_set_ui(a,23);
mpz_init_set_ui(b,45);
mpz_pow_ui(c,a,b);
gmp_printf("a: %Zd , b: %Zd, 23^45: %Zd",a,b,c);
return EXIT_SUCCESS;
}
But I'm still not there, since I have a overflow.
Question: Why do I get a overflow Question: What do I need to change in order to avoid the overflow?