-3

I have a code which runs and calculates a sequence of numbers and outputs it. When I run it on Python this is the number i get 89589789687112168422297691222737771124865819889385981395999564038551674847206437815235099730864284
But when I run the same code in c++ and output I get this 8.95898e+102

I want the whole integer to be printed in c++. How can I achieve this? It is a normal print statement in python :
print((2 ** q))
whereas in C++ I do this :
cout << pow(2, q)

Chandra Kanth
  • 427
  • 5
  • 14

1 Answers1

3
#include <iostream>

int main()
{
    long double d{ 89589789687112168422297691222737771124865819889385981395999564038551674847206437815235099730864284.L };
    std::cout << std::fixed << d;
}

Precision of long double is not sufficient to represent the number accurately, though. If you need more you'd have to use a library for arbitrary precision like GMP.

Swordfish
  • 12,971
  • 3
  • 21
  • 43