answersLogoWhite

0


Best Answer

the logic i have used is nCr => n!/(r!*(n-r)!) for example the outer loop counter is 'n' and the inner loop counter is 'r' , then the corresponding element of the pascal's triangle will be nCr. keep in mind that both the loops will have to start from zero. #include<stdio.h> main()

{

int num,i,j,k,space;

int difffact=1,diff,n,r,x,y,comb=0,nfact=1,rfact=1;

printf("please enter the number of lines\n");

scanf("%d",&num); k=num-1;

space=num-1;

for(i=0;i<num;i++)

{

k=space--;

for(;k>0;k--)

{

printf(" ");

}

for(j=0;j<=i;j++)

{

comb=0;

nfact=1;

rfact=1;

difffact=1; for(n=i;n>=1;n--)

nfact=nfact*n; for(r=j;r>=1;r--)

rfact=rfact*r; diff=i-j;

for(;diff>=1;diff--)

difffact=difffact*diff; comb=(nfact/(rfact*difffact));

printf("%d ",comb);

}

printf("\n");

}

}

User Avatar

Wiki User

βˆ™ 15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

βˆ™ 15y ago

the logic i have used is nCr => n!/(r!*(n-r)!) for example the outer loop counter is 'n' and the inner loop counter is 'r' , then the corresponding element of the pascal's triangle will be nCr. keep in mind that both the loops will have to start from zero. #include<stdio.h> main()

{

int num,i,j,k,space;

int difffact=1,diff,n,r,x,y,comb=0,nfact=1,rfact=1;

printf("please enter the number of lines\n");

scanf("%d",&num); k=num-1;

space=num-1;

for(i=0;i<num;i++)

{

k=space--;

for(;k>0;k--)

{

printf(" ");

}

for(j=0;j<=i;j++)

{

comb=0;

nfact=1;

rfact=1;

difffact=1; for(n=i;n>=1;n--)

nfact=nfact*n; for(r=j;r>=1;r--)

rfact=rfact*r; diff=i-j;

for(;diff>=1;diff--)

difffact=difffact*diff; comb=(nfact/(rfact*difffact));

printf("%d ",comb);

}

printf("\n");

}

}

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 12y ago

!Program Pascal_triangle

!implicit none

!integer ,allocatable::Pascal(:,:)

!integer(8) n ,k ,l

!print*,"Please Enter the rows of Pascal's Triangle:"

!read(*,*) n

!allocate (Pascal(n,n))

!do k=1,n

! do l=1,n

! if(l/=1)then

! Pascal(k,l)=0

! else

! Pascal(k,l)=1

! end if

! end do

!end do

!do k=2,n

! do l=2,n

! if(k/=l)then

! Pascal(k,l)=Pascal(k-1,l)+Pascal(k-1,l-1)

! else

! Pascal(k,l)=1

! end if

! end do

!end do

!do k=1,n

! print*,Pascal(k,1:k)

!end do !deallocate Pascal

!end program pascal's_triangle

!Uncomment(Ctrl+/) and run the program

!This program is a Fortran 90-95 program

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 11y ago

1

2 3

4 5 6

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the FORTRAN program for pascal's triangle?
Write your answer...
Submit
Still have questions?
magnify glass
imp