answersLogoWhite

0

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

16y ago

Still curious? Ask our experts.

Chat with our AI personalities

CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
More answers

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

16y ago
User Avatar

!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

User Avatar

Wiki User

13y ago
User Avatar

1

2 3

4 5 6

User Avatar

Wiki User

12y ago
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