Please help me out in this pattern program .
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Bunti360:
So, What should we do ? i mean can you explain the question in more detail?
Answers
Answered by
0
This is known as Pascal Triangle !
So we can get an element in a particular row by applying ncr formula !
Note : ----- indicates indention
Now,
In python , We can write the program as :
from math import factorial
(or)
#Finding factorial for further use
def fact(x):
---- if n == 0 :
------- return 1,
---- else :
-------- return n*fact(n-1)
#Taking user input
num = int(input ('Enter any Number'))
r = 0,
b = 0,
a = []
#Finding out numbers and adding to the list
while b <=num:
-----while r<=b:
--------a.append(int((fact(b)/fact(r))/fact(b-r)))
--------r += 1
------b += 1
------r = 0
c = 0
d = 1
#Printing rows
while c <= num:
------ e = int(((c)*(c+1))/2)
------ f = int(((d)*(d+1))/2)
------ print (a[e:f])
------ c +=1
------ d += 1
This is the code in python language to print Pascal Triangle !
P.S : I have written the same in SoloLearn ! Check that out ! Name : Sai Eshwar !
Hope you understand, Have a great day !
Thanking you, Bunti 360 !!
So we can get an element in a particular row by applying ncr formula !
Note : ----- indicates indention
Now,
In python , We can write the program as :
from math import factorial
(or)
#Finding factorial for further use
def fact(x):
---- if n == 0 :
------- return 1,
---- else :
-------- return n*fact(n-1)
#Taking user input
num = int(input ('Enter any Number'))
r = 0,
b = 0,
a = []
#Finding out numbers and adding to the list
while b <=num:
-----while r<=b:
--------a.append(int((fact(b)/fact(r))/fact(b-r)))
--------r += 1
------b += 1
------r = 0
c = 0
d = 1
#Printing rows
while c <= num:
------ e = int(((c)*(c+1))/2)
------ f = int(((d)*(d+1))/2)
------ print (a[e:f])
------ c +=1
------ d += 1
This is the code in python language to print Pascal Triangle !
P.S : I have written the same in SoloLearn ! Check that out ! Name : Sai Eshwar !
Hope you understand, Have a great day !
Thanking you, Bunti 360 !!
Answered by
2
C Code:
#include
void main()
{
int no_row,c=1,blk,i,j;
printf("Input number of rows: ");
scanf("%d",&no_row);
for(i=0;i {
for(blk=1;blk<=no_row-i;blk++)
printf(" ");
for(j=0;j<=i;j++)
{
if (j==0||i==0)
c=1;
else
c=c*(i-j+1)/j;
printf("% 4d",c);
}
printf("\n");
}
}
Similar questions