1,105,363 Community Members

Number bigger than 10 billion?

Member Avatar
george61
Junior Poster in Training
59 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

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;
		printf("\n%.0lf",expression);
		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("%.4lf",x1);
			printf("\nNumber is %.0lf\n",-c);
		break;}
		}
	return 0;
}
int main(){
	Equation();
	return 0;
}
Member Avatar
Ancient Dragon
Achieved Level 70
27,641 posts since Aug 2005
Reputation Points: 5,232 [?]
Q&As Helped to Solve: 3,037 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

You can write your own large number library using character arrays to hold each digit. Here is one such library (c++ class)

Member Avatar
iammirko
Light Poster
33 posts since Dec 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

#include<gmp.h>

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: