User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Legacy and Other Languages section within the Software Development category of DaniWeb, a massive community of 374,157 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,433 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Legacy and Other Languages advertiser:

Pascal's Triangle

Join Date: Apr 2008
Posts: 1
Reputation: saurabh41_scs is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
saurabh41_scs saurabh41_scs is offline Offline
Newbie Poster

Re: Pascal's Triangle

  #3  
Apr 13th, 2008
Originally Posted by Maddy1987 View Post



Coefficients in the expansion of (x+y)^n form a pattern which is useful for small values of n. It is known as Pascal's triangle.

n Pascal's triangle
1 1 1
2 1 2 1
3 1 3 3 1
4 1 4 6 4 1
5 1 5 10 10 5 1

Write a Matlab script to calculate and display this expression in the form of the triangle for the first 10 values of n. Use the sprintf command to display in a suitable format such as that shown above.





% A Program for Pascal's Triangle

if nargin ~=2
n=1:10;
s=4;
end

if n<55
a= n/10;
x=0;
y=0;
x2=0;
w=1;


hold on;

for m = 1:n-1
x = x2-a/2;
y = y-a/2*sqrt(2);
w = 1;

x2 = x;

for l = 1:m
x = x+a;
w = nchoosek(m,1);

end
end

else clf;
text(-0.2,0.5,' FontSize',23);
end;

hold off;
axis square;
axis equal;
axis off;


I had tried the question but i am not getting through it can any1 help me out in this problem.

hello i want to write code for this
in my opinion pascal triangle is:-
1
1 1
1 2 1
1 3 3 1

u wil find this by following prog:-
/*Program to Calculate the Pascal triangle */
#include<stdio.h>
int main()
{
int a[20][20];
int i,j,c,n,k;
printf("Enter how many lines do you want");
scanf("%d",&n);
a[1][1]=1;
a[2][1]=1;a[2][2]=1;
for(i=1;i<=n;i++)
{ for(j=1;j<=n-i;j++)
printf(" ");
if(i<3)
{
for(k=1;k<=i;k++)
{
printf("%d ",a[i][k]);
}
printf("\n");
}
else
{
a[i][1]=1;
printf("%d ",a[i][1]);
j=2;c=3;
while(j<i)
{
a[i][j]=a[i-1][c-2]+a[i-1][c-1];
printf("%d ",a[i][j]);
c=c+1;
j=j+1;
}
a[i][j]=1;
printf("%d\n ",a[i][j]);
}
}
getche();
}
Reply With Quote  
All times are GMT -4. The time now is 3:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC