|
1 DIAMOND Write a program that will ask the user for a whole number N between 3 and 10 and print a diamond of size N as shown in the sample run. Test your program for N = 4 and N = 7. Sample Run ENTER A WHOLE NUMBER BETWEEN 3 AND 10: 4 $ $-$ $-$-$ $-$-$-$ $-$-$ $-$ $ 2. PATTERNS Examine the pattern of the numbers in the triangle of size 7 shown below. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 ?? ?? ?? ?? 7 1 What should the last row should be? Write a program that will generate this triangle for any number of rows from 1 to 10. Test your program for N=7 and N=10. Hint: Look at the previous row to get values for the current row. 3 DIE TOSS A die is a cube with 6 equal sides numbered {1, 2, 3, 4, 5, 6}. Galileo performed the experiment of tossing three fair dice and summing the numbers that appear. He was interested in knowing which outcome was more likely: 1) Summing to 9 or 2) Summing to 10. Write a program to repeat Galileo's experiment N times and compare the number of times the sum is 9 with the number of times the sum is 10. Conclude which sum is more likely to appear. Test your program for N=400. Sample Run Enter the number of trials N: 400 The sum was 9: 45 times. The sum was 10: 47 times. this experiment implies that getting a 10 is more likely than getting a 9 in the toss of three dice. Note: Your experiment will more than likely have different numbers and could trigger a different conclusion. 4. REVERSE Write a program that asks the user for a sentence and prints the sentence reversing the words that are separated with "and". Thus ... BILL AND JIM ..... changes to ......JIM AND BILL..... . Assume all of the words are entered in upper case. Test your program with the follow sentence: you and I are going to the STORE to buy a hat and coat. Sample Run ENTER A SENTENCE: YOU AND ME BABY. ME AND YOU BABY. 5. CONSECUTIVE SUMS Write a program that will find and count the ways that a positive whole number can be written as the sum of two or more consecutive positive whole mumbers. Sample Run ENTER A WHOLE NUMBER : 45 THE CONSECUTIVE SUMS ARE: 45 = 1+2+3+4+5+6+7+8+9 45 = 5+6+7+8+9+10 45 = 7+8+9+10+11 45 = 14+15+16 45 = 22+23 NUMBER OF CONSECUTIVE SUMS = 5
|