any one can tell me how to do pascal triangle program

Edited 7 Years Ago by priyabalu87: n/a

Comments
For being plain lazy and arrogant

program needed

Hi
please find the code below. i have tested the program in linux. it might give some minor error in turbo-c but i hope u can correct those.

#include<stdio.h>

void drawPascalTriangle(int rows);
void getRow(int *prevRow, int prevRowSize, int *row);
void copyRow(int *prevRow, int *row, int rowSize);
void dispRow(int *row, int rowSize, int rows);

int main()
{
	int rows;
	printf("Enter no. of rows:");
	scanf("%d", &rows);
	
	drawPascalTriangle(rows);
	return 0;
}

void drawPascalTriangle(int rows)
{
	int prevRow[50];
	int row[50];
	int prevRowSize = 0;
	int rowSize = 0;
	int i;
	for(i=0;i<rows;i++)
	{
		getRow(prevRow, i, row);
		dispRow(row, i+1, rows);
		printf("\n");
		copyRow(prevRow, row, i+1);
	}
}

void getRow(int *prevRow, int prevRowSize, int *row)
{
	int i;
	for(i=0;i<prevRowSize;i++)
	{
		if(i==0)
		{
			*row = *prevRow;
		}
		else
		{
			*row = *(prevRow) + *(prevRow-1);
		}
		row++;
		prevRow++;
	}
	*row = 1;
}
void copyRow(int *prevRow, int *row, int rowSize)
{
	int i;
	for(i=0;i<rowSize;i++)
	{
		*prevRow = *row;
		prevRow++;
		row++;
	}
}
void dispRow(int *row, int rowSize, int rows)
{
	int i;
	for(i=0;i<rows-rowSize;i++)
		printf("    ");
	for(i=0;i<rowSize;i++)
	{
		printf("%4d    ", *row);
		row++;
	}
}

Stop hijacking threads. Start a new thread and learn how to read. Did you not read my previous post?

SHOW SOME EFFORT!! Your request and that of the OP just show how bloody well lazy the both of you are.

Sheesh.

thanks for giving program but i need only the concept of that program not the whole program.
give me concept of tsr and its uses

Comments
Try a search engine then
This article has been dead for over six months. Start a new discussion instead.