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

9th Mar 2022, 6:19 AM
Spykvng Hero
Spykvng Hero - avatar
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.
9th Mar 2022, 7:33 AM
Ani Jona šŸ•Š
Ani Jona šŸ•Š - avatar
- 1
3.142857 142857 142857 .....so on
9th Mar 2022, 6:23 AM
saurabh
saurabh - avatar