Pascals Triangle

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nuimstudent
    New Member
    • Mar 2008
    • 1

    Pascals Triangle

    Hey, I have to write a code which calculates pascals triangle using C. So Far I have the triangle with a right side allignment. As part of the assignment, we actually have to get the triangle to appear as a triangle.

    I have the function recursively calling itself as below;

    Code:
    int pascal_num (int n, int r)
    {
    	int pnum;
    	if (r == n || n == 1) {
    		return 1; }
    	pnum= (pascal_num (n, r-1) + pascal_num (n-1, r-1) );
    return pnum;
    }
    Any suggestions on how I can do this?
    I know I need ot use a for loop of some sort to print the spaces...
  • MonaLisaO
    New Member
    • Mar 2008
    • 13

    #2
    Did you ever do the one assignement where you needed to make a diamond or triangle pattern?

    Code:
    *
    **
    ***
    ****
    *****
    ******
    *******
    You could re-use that code.

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Use the printf() function .

      Comment

      Working...