More Pattern Problems

(Nested Loops)

  1. Rectangle. Write a C program with file name pat6.c that gets two numbers from the user. The first number is the number of rows; the second number is the number of asterisks in a row. It then should print a rectangle with that many rows, each row having the second number number of asterisks. For instance if the numbers are 3 and 4, the rectangle should be:
    ****
    ****
    ****
    
  2. Triangle. Write a C program with file name pat7.c that gets the number of rows from the user. It should print one asterisk in the first row, two asterisks in the second row, three asterisks in the third row, and so on. Each row contains one more asterisk that the preceding row. For instance, if the user enters a 5 then the program should print:
    *
    **
    ***
    ****
    *****
    
  3. Triangle. Write a C program with file name pat8.c that gets the number of rows from the user. It should print one asterisk in the first row, two asterisks in the second row, three asterisks in the third row, and so on. Each row contains one more asterisk that the preceding row. For instance, if the user enters a 5 then the program should print:
        *
       **
      ***
     ****
    *****
    
  4. Upside Down. Write a C program with file name pat9.c that gets the number of rows from the user. Its first row should contain that many asterisks. Each new row should contain one fewer asterisk than the previous. If the user enters a 5 the program should make
    *****
    ****
    ***
    **
    *
    
  5. Upside Down. Write a C program with file name pat10.c that gets the number of rows from the user. Its first row should contain that many asterisks. Each new row should contain one fewer asterisk than the previous. If the user enters a 5 the program should make
    *****
     ****
      ***
       **
        *
    
  6. Diagonal Line. Write a C program with file name pat11.c that gets the number of asterisks from the user. It should print one asterisk in each row, but the each new asterisk should be shifted over one more place. For instance if the user enters a 5, then the program should print:
    *
     *
      *
       *
        *
    
  7. Triangles. Write a C program with file name pat12.c that gets the number of triangles from the user. It should print that many triangles. The first triangle should have two rows. Each of the next triangles should each have one more row than the triangle coming before it. For instance, if the user enters a 4 then the program should print:
    *
    **
    *
    **
    ***
    *
    **
    ***
    ****
    *
    **
    ***
    ****
    *****
    
  8. Triangles. Write a C program with file name pat13.c that gets the number of triangles from the user. It should print that many triangles. The first triangle should have two rows. Each of the next triangles should each have one more row than the triangle coming before it. For instance, if the user enters a 4 then the program should print:
        *
       **
        *
       **
      ***
        *
       **
      ***
     ****
        *
       **
      ***
     ****
    *****
    
  9. Triangles. Write a C program with file name pat14.c that gets the number of triangles from the user. It should print that many triangles. The first triangle should have two rows. Each of the next triangles should each have one more row than the triangle coming before it. For instance, if the user enters a 4 then the program should print:
                 *
            *   **
        *  **  ***
     * ** *** ****
    **************