Join Sarthaks eConnect Today - Largest Online Education Community!
0 votes
16 views
asked in Computer by (63.2k points)

WAP to generate the following pascal’s triangle.

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1 

1 Answer

+1 vote
answered by (54.7k points)
selected by
 
Best answer

import java.io.*;

class pascal

{

public static void main ( ) throws IO Exception

{

InputStreamReader read = new InputStreamReader (System.in));

BufferedReader in = new BufferedReader (read);

int i, j, n;

int m [ ] =new int [20];

System.out.printIn (“Enter the size of the pascal triangle”);

n=Integer.parseIn(in.readLine ( ));

m [0] =1;

for (i=0; k<n; i++)

{

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

{

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

System.out.print(m[j]+” “);

System.out.printIn ( );

for (j=i+1; j>0; j--)

m[j] = m[j] + m[j – 1];

}

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

One Thought Forever

“There is a close connection between getting up in the world and getting up in the morning.“
– Anon
~~~*****~~~

Categories

...