//Exercises - that is all //Like the Jeffrey's Tube in StarTrek: GNDN (Goes Nowhere, Does Nothing) #include double bresenham(int n, double a, double b, double d) // a small variation of this algorithm is used for drawing straight lines // on graphic displays and plotters { for( int i = n; i > 0; i--) { if (d <= 0) d += a; else d -= b; } return d; } int sum_squares(int n) //The pattern of this algorithm is more important than the calculation { int i, sum; sum = 0; for( i = 1; i <= n; i++ ) { sum += i*i; } return sum; } int pow(int m, int n)// Given n and m returns m to the power n //This is a useful function to have in one's personal library //However there is faster algorithm than this one. { int i, p; p = 1; for( i = 1; i <= n; i++ ) p *= m; return p; } int factorial( int n) /* Given an integer n calculate the factorial of n using local integer p. 1. if n is less than or equal to 0 then 1.1. output an error message 1.2. set p to the default value 0 2. Otherwise 2.1. Set the product p to 1 2.2. For each integer i from 2 to n 2.2.1. multiply p by i 3. return the value of p */ { int p; if( n <= 0 ) { cerr << "Error in factorial( "<0\n"; // notice that 'cerr' is the right place for errors // even tho' it makes little difference in theory p = 0; }// here n was <= 0 and p is 0 else // n > 0 { p = 1; // here p is 1 for(int i = 2; i<=n; i++) { // here p is 1*2*3*...*(i-1) p *= i; //here p is 1*2*3*...*(i-1)*i }// end for //here i was n and and so p is 1*2*3*...*(n-1)*n } //here n was >0 and p is 1*2*3*...*(n-1)*n return p; } //--------------test harness---------------- int main() { cout << sum_squares(3) <