Blame view
lab1/pi_ser.c
467 Bytes
6a98a5afa lab1 |
1 2 3 |
#include <stdio.h> #include <stdlib.h> #include <string.h> |
adfef3110 add n |
4 |
#define N 1000000000 |
6a98a5afa lab1 |
5 6 7 8 |
int main (int argc, char** argv) { long long int n; long long int i; |
6a98a5afa lab1 |
9 10 11 12 13 14 |
double l_sum, x, h; n=N; if(argc==2) { |
adfef3110 add n |
15 |
n=atoll(argv[1]); |
6a98a5afa lab1 |
16 |
} |
adfef3110 add n |
17 |
|
6a98a5afa lab1 |
18 19 20 21 22 23 |
h = 1.0/n; l_sum = 0.0; for (i = 0; i < n; i ++) { |
9cad13733 MAJ |
24 |
x = (i+0.5)*h; |
6a98a5afa lab1 |
25 26 27 28 |
l_sum += 4.0/(1.0 + x*x); } l_sum *= h; |
adfef3110 add n |
29 30 |
printf("N=%lld, PI = %0.20g ",n ,l_sum); |
6a98a5afa lab1 |
31 32 33 |
return 0; } |