#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int create_matrix(int* matrix[], int row, int column, int size);
int create_pascals(int a, int b);

int main()
{
	//variable declaration
	int size;
	int* row = &size;
	int* column = &size;
	//output to the screen
	cout << " Please enter the size you want for your Pascal Triangle(# must be lesser than 10!!!): " << endl;
	cin >> size;
	//incase of number greater than 10 the program will terminate
	if(size>10)
	{
		cout<< " program will now terminate!!! thank you for using this program" << endl;
		exit(1);
	}
	//real stuff begins at this line
	else
	{
	//matrix declaration//
		int * *matrix= new int*[*row];
			for(int i=0; i<*row; i++)
			{
				matrix[i] = new int[*column];
			}
	//matrix declaration//

			//creating left blanks
	for(int row=0; row<size; row++)
	{
		for (int column=1; column<size-row; column++)
		{
			cout.width(2);
			cout << "D";
		}
		//introducing to fill the value
	for (int column=0; column<=row; column++)
	{
		cout.width(4);
		cout << create_pascals(row, column);
	}
	cout << endl;
	}

	//deletion
	for(int i=0; i<*row; i++)
		delete[] matrix[i];
	delete[]matrix;
	return 0;
	}
}
int create_pascals(int a, int b)
{
??????????????????????????????????????????????????????????????????????????????????
	int cons = 1, row;
	if (a< 0|| b<0|| b>a)
	{
		cout << " error!!! the program will now terminate." << endl;
		exit(1);
	}
????????????????????????????????????????????????????????????????????????????????
	else
	{
?????????????????????????????????????????????????????????????????????????????
	for (row=1; row<=b;row++, a--)
	{
		cons = cons*a/row;
	}
	return cons;
	}
????????????????????????????????????????????????????????????????????????????
}

i am trying to come up with code to make a pascal triangle using dynamic array this is what i have come up with so far. i need some explaination about some part of the code... thanks the code that i have question with is encircled with [???????], also can you tell me if my code is the right or wrong because i need it to be made with matrix(dymanic matrix) that why i declare it at a line.

thanks guys

int create_pascals(int a, int b)
{
/*
This section of the code is checking to make sure that the two parameters passed into the function are non-negative and that a is larger than b. Otherwise we exit straight away.
*/
	int cons = 1, row;
	if (a< 0|| b<0|| b>a)
	{
		cout << " error!!! the program will now terminate." << endl;
		exit(1);
	}

	else
	{
/*
This section of code is doing the calculation for what the method is calculating. By the looks of it, the second parameter passed into the function tells the method how many rows are in the pascal and the first parameter passed in tells it how long each row is.
*/
	for (row=1; row<=b;row++, a--)
	{
		cons = cons*a/row;
	}
	return cons;
	}

}

Hope this has helped,

darkagn

Comments
good explanation. ithelp

but why do i want to pass the two parameters into the function? what does those two parameters do? ... thanks

The first parameter tells you how long the first row (I guess this is the base of your pascal triangle perhaps?) is. The second parameter tells you how many rows there are (the height of your pascal triangle?)

Maybe it would help to ask the person that actually wrote the code for you than having us try to figure out what he meant when he wrote it.

This article has been dead for over six months. Start a new discussion instead.