**(HackerRank) Write a Modular C Programming code to solve Pi Series computers, Apply Problem Solving Framework to compute the value of pi using the above series**

In 1966 Donald G. Fink published a book entitled “Computers and the Human Mind”, which introduced the idea of artificial intelligence as it related to computers. One of the first problems he introduced to illustrate the utility of computers was the calculation of π. It was 1966, and computers were slow, and used punch cards! He postulates that a speed-up comes by way of simple calculation in the form of series.

Fink used a series of the following form:

π = 4/1 – 4/3 + 4/5 – 4/7 + 4/9 – 4/11 + 4/13…

Fink wants to Apply Problem Solving Framework to compute the value of pi using the above series with the help of modular C programming.

**Input Format**

First-line indicating value of N, the number of terms in the series.

**Constraints**

N should be greater than or equal to 100.

**Output Format**

Computed Series for pi.

**Sample Input 0**

```
100
```

**Sample Output 0**

```
Pi series = 3.1316
```

**Sample Input 1**

```
10
```

**Sample Output 1**

`Cannot compute pi series.`

**Refer :** C Programming HackerRank all solutions for Loops | Arrays | strings

**CODE:**

#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> void pi(int n) { int i; double sum=0; for(i=0;i<n;i++) { sum=sum+4*(pow(-1,i))/((2*i)+1); } printf("Pi series = %0.4lf",sum); } int main() { int n; scanf("%d",&n); if(n>=100) { pi(n); } else printf("Cannot compute pi series.\n"); return 0; }

**OUTPUT**

Congratulations, you passed the sample test case. Click the Submit Code button to run your code against all the test cases. Input (stdin) 100 Your Output (stdout) Pi series = 3.1316 Expected Output Pi series = 3.1316

**Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, MISC, Solved model question papers & Hacker Rank all solutions on the below page:**

Top 100+ C Programming codes – KLE Technological University