English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Need help in making a pascal triangle is turbo c........
need the shortest code as possible....
tnx

2006-10-14 00:57:31 · 3 answers · asked by Kenz 2 in Computers & Internet Programming & Design

3 answers

http://www.cs.ucl.ac.uk/staff/S.Bhatti/teaching/1b10/c/pascal_tri.c

http://www.chemie.fu-berlin.de/lehre/edv/src/pascal.c

http://barnyard.syr.edu/quickies/pascal.c

2006-10-14 01:10:57 · answer #1 · answered by Utkarsh 6 · 0 0

You must know the depth of the triangle beforehand. Not knowing this will make the generation of Pascal's triangle endless, and not admissible as a solution for any assignment. So, given a depth of n, declare an array of n x n, for now anyway. When the depth is 1, your first row, or row at index 1 is 1 in length. At depth = 2, it's 2 in length, or has 2 elements. Continuing this ad nauseam, we see that at depth n, the nth row has n elements. At each stage, sum up the elements in the n-1 row to get the current row. That should get you on your way. An array of n x n size is wasteful, you may wanna try to optimize it by using a ragged array to save space. I recommend the n x n to get started and then optimize when you have it working correctly.

2016-05-22 01:07:29 · answer #2 · answered by Anonymous · 0 0

//to get a pascal triangle
#include
#include
main()
{
int a[20][20],i,j;
clrscr();
printf("Enter n");
scanf("%d",&n);
for(i=0;i {
for(j=0;j {
if(j==0||i==j)
a[i][j]=1;
else
a[i][j]=a[i-1][j]+a[i-1][j-1];
printf(" %d",a[i][j]);
}
printf("\n");
}
getch();
}

This is the simplest code.
If u need further help (if any), contact me via mails.

2006-10-14 01:46:44 · answer #3 · answered by Innocence Redefined 5 · 0 0

fedest.com, questions and answers