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");
}
}
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");
}
}
!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
Not what did they program in Fortran, but what do they program in Fortran. Math. And lots of it. It is used in science and engineering applications for number crunching. It still is used, and in fact, it is the preferred language in finite element analysis programming and other work involving large amounts of calculation.
Solve simple intress usin fortran
1. FORTRAN is automated for the scientific purpose only. 2. FORTRAN stands for formula translation. 3. FORTRAN allows the formula directly and perform the task. 4. Allows name and character in short form(06 characters). 5. Easy to program a very complex task. 6. FORTRAN does not allows any header or footer files.
The name of the program. For example: program sum ! This is a comment. Your program's code goes here... end program sum
plz tel me befre 12 pm as i hv sessnal xam...
Pascal's triangle
pascal
The Sierpinski Triangle
pascals triangle is used to solve math problems that have chance of 2 different outcomes, such as flipping a coin
in the 11th century...
(a+b)7
35
1,4,6,4,1
Blaise Pascal.
Pascal didn't invent pascals triangle, he just made It popular. A Chinese mathematician invented it in about 1015.
Not what did they program in Fortran, but what do they program in Fortran. Math. And lots of it. It is used in science and engineering applications for number crunching. It still is used, and in fact, it is the preferred language in finite element analysis programming and other work involving large amounts of calculation.
The expanded binomial is another name for Pascal's triangle.