Programming Pascal’s Triangle

After long hours of studying and trial and error at Cogswell’s programming lab, I’ve finally completed my software engineering project.  The project was to re-create Pascal’s Triangle in C programming.

Sure, it may look easy, but I’ve stumbled across multiple problems with this project.  First I needed to decide how I was going to approach the problem, and how to create a formula for the program. Luckily, Pascal’s Triangle is a well known problem. There are plenty of examples online explaining how the triangle works.  After I figured out the formula, I then had to write a function so that the computation could take place and the output is printed to the computer screen. This is where I encountered the most difficulty, writing a function that prints the output in a triangular form. To achieve this, I had to use all the resources I had available to me:  the internet, tutors, and the professor of Cogswell’s software engineering program here. I decided to look online for examples of the same program.  Fortunately, a lot of examples online involved using methods that utilized arrays or the examples were just too sloppy, which meant that the project would be a good challenge for me. I thought to myself, surely there is a better way of making the program without utilizing arrays, and sure enough there was.

My solution to this problem was to make use of the “for loop,” a conditional statement where if all the statement are true, it will perform the indicated piece of code, or if the statements are false, it would proceed to a different set of instructions. At this point I thought I’ve finally finished my project, and all I had to do was to write the “for loop.” Sure enough, this is the point where I stumbled across the issue I mentioned earlier.  I had to figure out how to make the output print out in a triangular form.  The method I used to approach this was through trial and error with help from the debugger. The debugger allowed me to figure out where and when the program was printing the output, which allowed me to change the code to make the necessary adjustments so that it printed out correctly.

Finally I finished my project. This project may not seem like much, but I did get to learn valuable lessons from it. What I really learned from this project was how to use “for loops” and how to successfully use the debugger in order to find out where the problem is located. These tools are essential for any programmer to learn. The “for loops” are an important part for programming and can be difficult to understand as a first time programmer. Next time I am asked to write a program that uses “for loops” I can be assured that even though I may run into some problems, I will always know how to debug the program.

Tags: , ,

Comments are closed.