0
The constant Pi is defined as the ratio of a circle's circumference to its diameter.
The constant Pi is defined as the ratio of a circle's circumference to its diameter. Pi is an irrational number, meaning that it's digits never end or repeat in any known way. Task: Given an integer N as input, find and output the Nth decimal digit of Pi. Input Format: An integer: 0<N<1000 Output Format: An integer, representing the Nth decimal digit of Pi. Sample Input: 12 Sample Output: 9
3 Answers
+ 2
Easy version: Copy the digits from some website and store as constant string pi. Access pi[n] to get n-th digit.
Fun but tough: Use the algorithm by Frabrice Bellard. It is fast andavoids numeric overflow for languages like C that don't have arbitrary precision types.
- 1
3.142857 142857 142857 .....so on