4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by dkalita
Featured Replies
  • @dkalita, We do not freely give out code on these forums unless the poster shows some effort. Since you are a "newbie", you need to read this: [URL="http://www.daniweb.com/forums/announcement118-2.html"]http://www.daniweb.com/forums/announcement118-2.html[/URL] Read More

0

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++;
	}
}
0

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.

-1

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.