Here is an example code that takes input from the user for the number of rows in the triangle and the shape of the triangle. We use a for loop to iterate over the rows and a while loop to create the desired shape of the triangle.
main.m581 chars26 lines
This code takes input from the user for the number of rows and the shape of the triangle. Based on the shape input, it uses a while loop to create the triangle shape. If the shape is increasing, we iterate through rows using a while loop and for each row we print the necessary number of asterisks using another for loop. If the shape is decreasing, we iterate through the rows again but this time, we print the asterisks in descending order using a similar while and for loop. Finally, if an invalid shape is provided, the program alerts the user.
gistlibby LogSnag