edelossantos
asked on
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][c ol-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 `++'
/* 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]+
}
// 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 `++'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.