GNU Multiple Precision Arithmetic Library - Example

Example

Here is an example of C code showing the use of the GMP library to multiply and print large numbers:

#include #include #include int main(void) { mpz_t x; mpz_t y; mpz_t result; mpz_init(x); mpz_init(y); mpz_init(result); mpz_set_str(x, "7612058254738945", 10); mpz_set_str(y, "9263591128439081", 10); mpz_mul(result, x, y); gmp_printf("\n %Zd\n*\n %Zd\n--------------------\n%Zd\n\n", x, y, result); /* free used memory */ mpz_clear(x); mpz_clear(y); mpz_clear(result); return EXIT_SUCCESS; }

This code calculates the value of 7612058254738945 × 9263591128439081.

Compiling and running this program gives this result. (The -lgmp flag is used if compiling on Unix-type systems.)

7612058254738945 * 9263591128439081 -------------------- 70514995317761165008628990709545

Read more about this topic:  GNU Multiple Precision Arithmetic Library

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)