|
1. STOP SIGN Write a program that will generate and print out a STOP sign below of size N, where N is an integer >= 3. The stop sign should be an octagon with N stars on each side. For example, with an input of N=4 the stop sign should appear as follows: * * * * * * * * * * * * * * * * * * * * * * * * Print a STOP SIGN for each of the following values of N: 3,4,5 2. SILLY-SORT Suppose you translate a whole number into a string of words, one word for each digit, followed by a single space. For example, the number 407 becomes the word string: "FOUR ZERO SEVEN". Now comes the fun part. You are to write a program to enter two whole numbers, and to print out the numbers in Silly-Sort order, sorted by their word strings. In particular, given the two numbers 17 53 the program output for the Silly-Sorted pair should be printed in the following order: 53 17 because "FIVE THREE" comes before "ONE SEVEN" as strings. Sample Run Enter two numbers: 17 53 The Silly-Sort order is 53 17 Test your program with the following collection of pairs: 79 662 434 5984 5554 5555 3. CIRCULAR NUMBERS A whole number is said to be CIRCULAR if, when you multiply the number by its units decimal digit, the result is the number with its decimal digits rotated to the right, where the units digit becoming its high-order digit. For example, 102564 is a circular number because of the multiplication: 102564 x4 -------- 410256 Write a program to find the smallest circular number with a given units digit. Sample Run For units digit = 4 The smallest CIRCULAR NUMBER = 102564. Test your program for N=4,7,9. 4. RATIONAL APPROXIMATION The rational number (fraction) 22/7 is a good approximation to the real number Pi = 3.141592654.... Are there better RATIONAL APPROXIMATIONS? Write a program that will find the best rational approximation M/N to a number X among all rational numbers (fractions) with denominators is less than or equal to D. The best approximations is defined to be the one that has the smallest difference: ABS(M/N - X). If more than one have the same smallest difference, the one with the smallest denominator should be chosen. Sample Run: The number X to approximate = 3.14159 The maximum denominator D = 10 The best RATIONAL APPROXIMATION = 22/7 Test your program for X= 3.14159, D=100 X=3.14159, D=1000 5. AMAZING WALKS Given an NxN square divided into N^2 unit cells, it is always possible to walk from the upper left cell, cell 1 to the lower left cell, cell N^2 - N +1, by stepping from one cell to a neighboring cell ( one that shares a common side) until you arrive at your goal having passed through every cell exactly one time. For example, here is a sample AMAZING WALK for N=3 ---------------- | | | | | 1*****2***3 | | | | * | ------------*--- | | | * | | 4***5 | 6 | | * | * | * | ---*---*----*--- | * | * | * | | 7 | 8****9 | | | | | ---------------- Write a program to find one AMAZING WALK in a square of size NxN. Sample Run N = 3 An AMAZING WALK is 1 2 3 6 9 8 5 4 7. Test your program with the following values for N: 4, 6, 10.
|