//========================================================================= #define PROGRAMMER "BAHN, William" #define PROG_CODE "bahw" #define COURSE "ECE-1021" #define YEAR (2003) #define TERM "Fall" #define SECTION (0) #define ASSIGNMENT "RWA 4.8" #define REVISION (0) #define TITLE "Real World Application from Section 4.8" #define SUBTITLE "Summing a Series" #define EMAIL "wbahn@eas.uccs.edu" #define FILENAME "rwa0408.c" //========================================================================= // PROBLEM: // // MODIFIED FROM TEXT // // Sum the series: // // y(n) = SUM{i=1 to n) 1/(i^2) // // Sum the series two ways: // 1) Starting with the least significant term // 2) Starting with the most significant term // // PSEUDOCODE // 1) REM: Print Header // 2) GET: number of terms from User // 3) REM: Determine if year is a leap year // 4) REM: Determine the day-of-week that year starts on // 5) REM: Print Calandar // 6) EXIT program //== INCLUDE FILES ======================================================== #include // printf(), scanf(), EOF #include // sqrt() #include // gotoxy() //== FUNCTION PROTOTYPES ================================================== void PrintHeader(void); //== MAIN FUNCTION ======================================================== int main(void) { long int i, terms; double sum; PrintHeader(); printf("\n"); // Print a blank line printf("Enter the number of terms to sum: "); scanf("%li", &terms); // Summing Forward for(sum = 0.0, i=1; i<=terms; i++) sum += 1.0 / ( (double) i * (double) i ); printf("Sum (starting with Most Sig Term): %.14f\n", sum); for(sum = 0.0, i=terms; i>0; i--) sum += 1.0 / ( (double) i * (double) i ); printf("Sum (starting with Least Sig Term): %.14f\n", sum); printf("\n"); printf("PROGRAM TERMINATED"); return(0); } //== SUPPORT FUNCTIONS ==================================================== void PrintHeader(void) { printf("========================================" "=======================================\n"); printf("Course....... %s-%i (%s %i)\n", COURSE, SECTION, TERM, YEAR); printf("Programmer... %s (%s)\n", PROGRAMMER, PROG_CODE); printf("Assignment... %s (Rev %i) (Source Code in %s)\n", ASSIGNMENT, REVISION, FILENAME); printf("Description.. %s\n", TITLE); printf(" %s\n", SUBTITLE); printf("========================================" "=======================================\n"); return; }