Start New Discussion within our Software Development Community

Here is code for hexagonal and pentagonal numbers. I need type that stores something bigger than 10 billion. Double works fine to about 8.4 billion. Of course I tried using long long and unsigned long long but it's still not working. Please repair this code because it overflows now matter what I do or explain how to use GMP library. I'm using CodeBlocks 10.5. Best regards.

#include <stdio.h>
#include <math.h>

double Pentagonal(int n){
	double P = 0;
	P = (3*n*n - n) / 2;
	P = -P;
	return P;
double Equation(){
	double x1,x2,remainder = 0;
	//where the cycle starts
	int n = 166;
	//variable for the remainder
	int x = 0;
	//quadratic equation quotients
	int a = 2;
	int b = -1;
	double c = 0;
	for(n; n<33000; n++)
		{c = Pentagonal(n);
		double expression = b*b - 4*a*c;
		double root = sqrt(expression);
		x1 = (-b + root)/(2*a);
		x = (-b + root)/(2*a);
		remainder = fmod(x1,x);
		x2 = (-b - root)/(2*a);
		if(remainder == 0)
			printf("\nNumber is %.0lf\n",-c);
	return 0;
int main(){
	return 0;

Just download, uncompress and compile the GNU Bignum files from here. Use:


in all your files. Now you can use GMP data types like mpz_t to work with arbitrary precision numbers.

Add, -lgmp flag (i,e link the GMP library) while compiling your final program.

This article has been dead for over six months. Start a new discussion instead.