
- Forum
- Programming Talk
- C and C++
- Generate Pascal's triangle
Generate Pascal's triangle
This is a discussion on Generate Pascal's triangle within the C and C++ forums, part of the Programming Talk category; I need to write a C++ program to generate pascal's triangle. Please help me.......
-
12-24-2010, 11:26 AM #1
- Join Date
- Dec 2010
- Answers
- 32
Generate Pascal's triangle
I need to write a C++ program to generate pascal's triangle.
Please help me....
-
03-09-2011, 01:05 AM #2
#include <iostream>
using namespace std;
void printrow(int r, int q[][13]) {
int e;
for (e=0; e<13; e++) {
cout << q[r][e] << " ";
}
cout << endl;
return;
}
int main()
{
int n, p[13][13];
int count = 0;
cout << "Enter a row number."<< endl;
cin >> n;
while (n >= 0) {
int count = 0;
cout << "Enter a row number."<< endl;
cin >> n;
int x, y;
for (x=0; x<=n; x++) {
count++;
for(y=0; y<=(count-1); y++) {
if (x>n || y>x)
{
p[x][y] = 0;
cout<<p[x][y];
}
else if (y==0 || y==x)
{
p[x][y] = 1;
cout<<p[x][y];
}
else
{
p[x][y] = p[x-1][y-1] + p[x-1][y];
cout<<p[x][y];
}
for (x=0;x<=n;x++ )
{
count++;
for (y=0;y<=n;y++)
{
cout << p[n][y] <<" ";
}
}
}
return 0;
}
This code generates pascal triangle!!
it was written by my brother...
hope it will help u
Swapwarick

Reply With Quote





