Skip to content

Instantly share code, notes, and snippets.

@rszewczyk
Created November 14, 2017 23:12
Show Gist options
  • Save rszewczyk/473d7269fb840bff8b6191d1d2699a0b to your computer and use it in GitHub Desktop.
Save rszewczyk/473d7269fb840bff8b6191d1d2699a0b to your computer and use it in GitHub Desktop.
CMSC 104, Class 20 - 11/14/2017

In Class Assignment

Create file called stars2.c and paste the contents of stars.c from Class 16 into it.

Compile and run the program to make sure it works. Then modify the the code so that the part that prints the stars uses for loops instead of while loops (the part from line 18 to the end).

Submit your program to me on Slack. If you don't finish today, it is due by the end of next class (11/16/2017).

Optional Practice Problem

Copy the contents of either stars.c from Class 16, or stars2.c into a file called stars3.c. You can choose either one of them depending on your preference for while loops or for loops.

Modify the program in stars3.c to print a number of rows equal to the user input, but instead of increasing the number of stars by one for each row, increase them by two. So the output will look like:

Enter an integer: 5
*
***
*****
*******
*********

Then modify stars3.c so that it prints the stars in this arrangement:

Enter an integer: 5
    *
   ***
  *****
 *******
*********

Then modify stars3.c so that it prints a tree shape:

Enter an integer: 5
    *
   ***
  *****
 *******
*********
   ***
   ***

Note that the row count is still the size of the triangle part (the trunk is added on).

Also, the size of the trunk should be scaled somehow to the row count. For example:

Enter an integer: 7
      *
     ***
    *****
   *******
  *********
 ***********
*************
    *****
    *****
    *****
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment