[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Non-Recursive Pascal's Triangle

Posted on 2004-10-24
Medium Priority
1,322 Views
// 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) {

for(int i = 1; i == k; 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 `++'
0
Question by:edelossantos
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
1 Comment

LVL 4

Accepted Solution

pankajtiwary earned 2000 total points
ID: 12396503
Hi edelossantos,

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

Cheers!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
###### Suggested Courses
Course of the Month13 days, left to enroll