Problem

Write a program that takes a command-line argument n and creates an n-by-n boolean matrix...

Write a program that takes a command-line argument n and creates an n-by-n boolean matrix with the element in row i and column j set to true if i and j are relatively prime, then shows the matrix on the standard drawing (see EXERCISE 1.4.16). Then, write a similar program to draw the Hadamard matrix of order n (see EXERCISE 1.4.29). Finally, write a program to draw the boolean matrix such that the element in row n and column j is set to true if the coefficient of xj in (1 + x)i (binomial coefficient) is odd (see EXERCISE 1.4.41). You may be surprised at the pattern formed by the third example.

EXERCISE 1.4.16

Write a program that takes an integer command-line argument n and creates an n-by-n boolean array a[] [] such that a[i] [j] is true if i and j are relatively prime (have no common factors), and false otherwise. Use your solution to EXERCISE 1.4.6 to print the array. Hint: Use sieving.

EXERCISE 1.4.6

Write a code fragment that prints the contents of a two-dimensional boolean array, using * to represent true and a space to represent false. Include row and column indices.

EXERCISE 1.4.41

Binomial coefficients. Write a program that takes an integer command-line argument n and creates a two-dimensional ragged array a[] [] such that a[n] [k] contains the probability that you get exactly k heads when you toss a fair coin n times. These numbers are known as the binomial distribution: if you multiply each element in row i by 2n, you get the binomial coefficients—the coefficients of xk in (x+1)n—arranged in Pascal’s triangle. To compute them, start with a [n] [0] = 0.0 for all n and a[l] [1] = 1.0, then compute values in successive rows, left to right, with a[n][k] = (a[n-l] [k] + a[n-l] [k-1]) / 2.0.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2.4