Computer Science, asked by Incredible29, 1 year ago

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?
Incredible29: write thr program for this
Bunti360: in which language ?
Bunti360: I know how to write it in Python programming language !
Incredible29: java
Bunti360: oh
Incredible29: okk .. write in python
Bunti360: Ok. !
Bunti360: you can do that in java too !
Bunti360: Just find ncr of the number and add that into a list !

Answers

Answered by Bunti360
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 !!

Incredible29: thnx :)
Bunti360: Anytime !!.
Incredible29: my sololearn profile is Kusumita Ghose :)
Bunti360: Great ! and dp?
Bunti360: Thank you for choosing my answer as the brainliest !
Incredible29: same ...
Incredible29: ur welcm :)
Incredible29: wait a sec... i am following u there
Bunti360: no results found for your name !
Bunti360: wow !
Answered by Lucky20690
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");
}
}

Incredible29: thnk u :)
Similar questions