1、CHAPTER 1Chapter 1, Pages 16-17Problem 1.a This statement is a poorly phrased version of Fermats last theorem. We know that we can find n 2 for which the equation holds. Fermat scribbled a note on a text margin indicating that he had found the solution for n = 2. Unfortunately, the proof died with h
2、im. Because the statement is phrased as a question rather than a clearly defined algorithm, it lacks definiteness.Problem 1.b This statement violates not only the rules of mathematics, but the criterion of effectiveness. We can compute only those things that are feasible, and division by zero is mat
3、hematically undefinedPage 17, Exercise 3#include #include #include#define TRUE 1#define FALSE 0#define MAX_STRING 100 void truth_table(int);int main() int n;printf(n:(=0): ); scanf(%d, &n); while (n = 0) /*error loop */ printf(truth_table(n);void truth_table(int n)/* generate a truth_table by transf
4、orming # of permutations into binary */int i,j, div, rem;char stringMAX_STRING; for (i=0; i 0; j-)/*number of bits needed for each row*/ rem = div%2;div = div/2;if (!rem) strcat(string,FALSE else strcat(string, TRUE%sn, string);Page 17, Exercise 4#includeint min(int, int); #define TRUE 1int main()in
5、t x,y,z;x:x);y: scanf (y);z:z);if (min(x,y) & min(y,z) /*x is smallest */ printf(%d , x);if (min(y,z) printf (%d %dn, y,z);else printf(%d%dn, z, y);else if (min(y,x) & min(y,z) /*y is the smallest */ printf(, y);if (min(x,z) printf (, x,z);, z,x);else%d %d %dn, z, y, x);int min(int a, int b) if (a 1
6、; i-) answer *= i;return answer;Page 17, Exercise 8int iterFib(int); int recurFib(int);%d Fibonacci is %d.n, n, iterFib(n);, n, recurFib(n);int recurFib(int n)if (n=0) | (n=1) return 1; return recurFib(n-1) + recurFib(n-2);int iterFib(int n)int fib, fib1, fib2;if (n = 0) | (n = 1) return 1; fib1 = f
7、ib2 = 1;for (i = 2;=n; i+) fib = fib1+fib2; fib2 = fib1;fib1 = fib;return fib;Page 17, Exercise 9double recurBinom(int, int); double iterBinom(int, int); double recurFact(int n);int main()int n,m;m:m); while (m %d m: %d Recursive Binomial coefficient is %f.n, n, m, recurBinom(n,m); %d Iterative Bino
8、mial coefficient is %f.n, n, m, iterBinom(n,m);double iterBinom(int n, int m)/* defined as n!/(m! - (n-m)!)*/ int i;double nFact, mFact, nMinusMFact; if (n = m) return 1;if (n=0) | (n = 1) nFact = 1; elsenFact = 1; i-) nFact *= i;if(m=0) | (m = 1) mFact = 1; else mFact = 1;for (i = m; i-) mFact *= i;if ( (n-m) = 0) | (n-m) = 1) nMinusMFact = 1;nMinusMFact = 1;for (i = n-m; i-) nMinusMFact *= i;return nFact/(mFact*nMinusMFact);double recurBinom(int n, int m)return recurFact(n)/(recurFact(m)*recurFact(n-m);Page 17, Exercise 11#define Tower1 1#defin
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1