Non-Recursive Pascal's Triangle

// Does not compile

/* non-recursive Pascal's Triangle      
   programmer: Enrique De Los Santos*/

#include <iostream>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

#define MAX 12
typedef int PascalArray[MAX][MAX];
PascalArray p;

int main() {

  int c3(int n, int k) {
   
    answer = 1;
   
    for(int i = 1; i == k; i++)
      answer = answer *((n + 1 - i)/i);

  }

  int col, row;

    for(row = 0; row < MAX; row++)
      for(col = 0; col <= row; col++) {
      if(col == 0)
        p[row][col] = 1;
      else
        if(row == col)
          p[row][col] = 1;
        else
          p[row][col]=p[row-1][col]+p[row-1][col-1];

      }

  // triangle display
  for(row = 0; row < MAX; row++) {
    for(col = 0; col <= row; col++)
      cout << "%5d" << p[row][col] << endl;

  }

}

out:

[edeloss2@pegasus part3]$ g++ nonRPasc.cpp
nonRPasc.cpp: In function `int main()':
nonRPasc.cpp:16: parse error before `{'
nonRPasc.cpp:20: `k' undeclared (first use this function)
nonRPasc.cpp:20: (Each undeclared identifier is reported only once
nonRPasc.cpp:20: for each function it appears in.)
nonRPasc.cpp:21: `answer' undeclared (first use this function)
nonRPasc.cpp:21: `n' undeclared (first use this function)
nonRPasc.cpp: At top level:
nonRPasc.cpp:27: parse error before `for'
nonRPasc.cpp:27: parse error before `;'
nonRPasc.cpp:27: syntax error before `++'
nonRPasc.cpp:28: syntax error before `<='
nonRPasc.cpp:28: syntax error before `++'
nonRPasc.cpp:40: parse error before `;'
nonRPasc.cpp:40: syntax error before `++'
nonRPasc.cpp:41: syntax error before `<='
nonRPasc.cpp:41: syntax error before `++'
edelossantosAsked:
Who is Participating?
 
pankajtiwaryCommented:
Hi edelossantos,

Same here take the definition of the function c() out of main and then compile.

Cheers!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.