Author: Anonymous Language: cpp
Description: No description Timestamp: 2007-10-17 15:17:31 -0400
View raw paste Reply
  1. void main(){
  2.        
  3.         int n, i;
  4.         long double pi = 4, d=3;
  5.  
  6.         cout << "Enter the number of terms you wish take Pi to." << endl;
  7.         cin >> n;
  8.  
  9.         for (i = 0; i < n; i++){
  10.                
  11.                 if (i % 2 == 0)
  12.                         pi = pi - (4/d);
  13.                 else
  14.                         pi = pi + (4/d);
  15.                 d += 2;
  16.         }
  17.         cout << "Pi = " << pi << endl;
  18. }
View raw paste Reply