Hi all, this is my first post (possibly ever, can't remember when i last came on =P)

Anyways, I am fairly good in the C language, far from expert.

I got the idea of making a program that calculates pi. I made it and using a long double, I could calculate pi accurately to 19 decimal places, which makes total sense considering I was using a long double.

So I wasn't satisfied, and realized that to accomplish anything better than 19 decimal places, I would need to use GMP.

So I installed GMP for DevC++ on Windows 7. All goes well, I even tested some examples I found online.

So after reading the GMP manual, as well as countless examples of GMP code online, this is all I've been able to do. If anybody doesn't mind looking, that would be great. I just ask that nobody gives me the answer on a silver platter, I really want to learn this, and I just couldn't do it on my own. If anybody has the time to help, i would appreciate guidance on which GMP functions to use, and why I should be using them.

Sorry for such a long intro. Here is the code I have been able to write with the knowledge I gained from reading the GMP manual and examples online:

As of right now, I have first_term related code turned off, simply because I'm not sure how I will go about implementing 16 to the K power using GMP.Code:`#include <stdio.h>`

#include <stdlib.h>

#include <math.h>

#include <GMP.h>

int main ()

{

mpf_set_default_prec (15);

int x=1; //loop

mpf_t k; //series variable (should start equal to 1)

mpf_init(k); //set equal to 0 *I THINK*

mpf_t first_term, second_term, third_term, fourth_term, fifth_term; //terms of series broken down to guarenteed proper order of opperations (revised from v0.1)

mpf_t pi_term;

mpf_t final_pi;

while(x <= 10)

{

//beginning of series

//first_term = (1)/pow(16,k);

//mpz_mul_ui(first_term,16,k);

//mpf_ui_div(first_term,1,first_term);

//second_term = (4)/((8*k)+1);

mpf_mul_ui(second_term,k,8);

mpf_add_ui(second_term,second_term,1);

mpf_ui_div(second_term,4,second_term);

//third_term = (2)/((8*k)+4);

mpf_mul_ui(third_term,k,8);

mpf_add_ui(third_term,third_term,4);

mpf_ui_div(third_term,2,third_term);

//fourth_term = (1)/((8*k)+5);

mpf_mul_ui(fourth_term,k,8);

mpf_add_ui(fourth_term,fourth_term,5);

mpf_ui_div(fourth_term,1,fourth_term);

//fifth_term = (1)/((8*k)+6);

mpf_mul_ui(fifth_term,k,8);

mpf_add_ui(fifth_term,fifth_term,6);

mpf_ui_div(fifth_term,1,fifth_term);

//pi_term = second_term - third_term - fourth_term - fifth_term;

mpf_sub(pi_term,second_term,third_term);

mpf_sub(pi_term,pi_term,fourth_term);

mpf_sub(pi_term,pi_term,fifth_term);

//pi_term = pi_term * first_term;

mpf_mul(pi_term,pi_term,first_term);

//end of series formula, at this point, pi_term is result of plugging value in for k

//final_pi = final_pi + pi_term; //Adds results from series

mpf_add(final_pi,final_pi,pi_term);

mpf_clear (first_term);

mpf_clear (second_term);

mpf_clear (third_term);

mpf_clear (fourth_term);

mpf_clear (fifth_term);

mpf_clear (pi_term);

mpf_add_ui(k,k,1); //k increases incrementally to 100,000 (should be more, but this program only does to 15 decimal places, so it is not necesary)

x++; //x increases incrementally to satisfy while() loop, will break from loop at x<=100000

}

system("CLS"); //clears command prompt/terminal window, change to (system("CLEAR"); in Mac)

printf("Pi Calculator v0.2 By Bryan Keller\nSource code available upon request\nFormula used: Bailey Borwein Plouffe formula (BBP formula)\n");

gmp_printf("\n\n%Fd\n\n",final_pi);

system("PAUSE");

return 0;

}

Anyways, even with the useless 16 to the K power code commented out, the program stops responding upon first open. If anybody compiles it for themselves, you will see that through trial and error, i have figured out how to remove all errors and warnings, excluding the 16 to the K power code, which as I already mentioned, has been commented out anyways.

You'll also notice that the default precision is 15, this is simply to see if i can replicate something close to the results I was getting without GMP. After I accomplish that, I can work my way up to larger decimals.

Anyways, based on my minimal knowledge, I think the problem has to do with the program using a LOT of resources. Maybe I'm wrong, but I am declaring a lot of variables, so that's my best guess.

Thanks again for looking, and sorry for the long post, but I just want to make this as clear as possible =)