I am attempting to use the Bailey-Borwein-Plouffe algorithm, ((4/(8n+1))-(2/(8n+4))-(1/(8n+5))-(1/(8n+6)))/16^n for the nth digit of pi.

Here is my code:

I'm getting the wrong answer and I don't know if I'm handling the hexadecimal conversion correctly.Code:#include <stdio.h> int main(void){ float n, pi_digit, hex_base, pi; for(n=0, hex_base=1; n<=20; n++) { pi_digit = 4 /(8 * n + 1); pi_digit -= 2 / (8 * n + 4); pi_digit -= 1 / (8 * n + 5); pi_digit -= 1 / (8 * n + 6); pi_digit /= hex_base; hex_base *= 16; printf("%x ",pi_digit); } getchar (); }