// Arup Guha
// 9/28/09
// COP 3223
// Program for Exam #1 Review 
// Sums 1-1/3+1/5-1/7+...+1/9997-1/9999 and prints out
// this value to 5 decimal places. This is an approximation for pi/4.

#include <stdio.h>

int main() {
    
    int i;
    int sign = 1; // Keeps track of if we're adding or subtracting.
    double sum = 0;
    
    // Loop through each term.
    for (i=1; i<10000; i=i+2) {
        
        // Notice that we use 1.0 to force the double division.
        sum = sum + sign*1.0/i;
        
        // This is an easy way to toggle a sign.
        sign = -sign;
    }
 
    // The first print is requested, while I just added the second one
    // for kicks.   
    printf("Pi/4 is approximately %.5lf.\n", sum);
    printf("So, Pi is about %.5lf\n", 4*sum);
    
    system("PAUSE");
    return 0;
}
