Changes between Initial Version and Version 1 of cypress/Programming/ApproximatePi/CExample
- Timestamp:
- 05/14/15 14:40:19 (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
cypress/Programming/ApproximatePi/CExample
v1 v1 1 = Ex12sq.c = 2 {{{#!C 3 /* 4 C sample 5 ex12sq.c 6 */ 7 #include <stdio.h> 8 #include <stdlib.h> 9 10 int main (int argc, char *argv[]) { 11 int i,n; 12 double x; 13 14 if (argc < 2){ 15 printf("%s [number of terms]\n",argv[0]); 16 exit(-1); 17 } 18 19 n = atoi(argv[1]); 20 printf("Start n=%d\n",n); 21 22 x=0.0; 23 24 for (i = 0 ; i < n ; i+=2){ 25 x += 1.0 / (double)(2 * i + 1); 26 x -= 1.0 / (double)(2 * i + 3); 27 } 28 printf("n=%d Pi=%1.16f\n",n,4.0 * x); 29 } 30 }}}