Number bigger than 10 billion?
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;
}
george61
Junior Poster in Training
59 posts since Jul 2010
Reputation Points: 10
Solved Threads: 6
Skill Endorsements: 0
You can write your own large number library using character arrays to hold each digit. Here is one such library (c++ class)
Ancient Dragon
Achieved Level 70
32,274 posts since Aug 2005
Reputation Points: 5,852
Solved Threads: 2,590
Skill Endorsements: 70