1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rama09 [41]
3 years ago
12

I need to create a function that returns Pascal's Triangle with n rows, where n is an int argument.

Computers and Technology
1 answer:
Ede4ka [16]3 years ago
6 0

A function that returns Pascal's Triangle with n rows:

//import necessary headers

public class Pascal_Triangle {

   // calculate factorial  

   static int factorial(int n)

   {

       int fact = 1;

       int i;

       for(i=1; i<n; i++)

       {

           fact*=i;

       }

       return i;

   }

   // Actual code to display the //pascal triangle

   static void display(int n)  

   {

       int i;

       int line;

       for(line=1;line<=n;line++)

       {

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

           {

               System.out.print((factorial(line)/factorial(line-i) * factorial(i)) + " ");

           }

           System.out.println();

       }

   }

   // To read user input

   public static void main(String[] args){  

       BufferedReader breader=new BufferedReader(new InputStreamReader(System.in));

       int n;

       System.out.println("Enter the size for creating Pascal triangle");

       try {

           n = Integer.parseInt(breader.readLine());

       }

       catch(Exception e){

           System.out.println("Please enter a valid Input");

           return;

       }

       System.out.println("The Pascal's Triangle is");

       display(n);

   }

}

You might be interested in
What blank operating system is usually used in personal computers
LenaWriter [7]

The market of personal computers is dominated by Microsoft with their OS called Windows. Windows 10 and Windows 7 are most popular operating systems.

7 0
3 years ago
two technicians are describing engine operation and requirements at high altitude technician a says that when traveling at high
fredd [130]

Technician B is the correct answer

7 0
3 years ago
B. List any four major drawbacks of the first generation computer​
d1i1m1o1n [39]

Answer:

Terribly low storage space, limited to mathematics/computing, required entire rooms to use, and low information yield for hours of processing.

Explanation:

3 0
3 years ago
3. Show the stack with all activation record instances (with all fields), when execution reaches position 1 in the following ske
Marianna [84]

Answer:

Check the explanation

Explanation:

The chain of static links is being referred to as static chain if it connects a particular activation record instances (ari) in the stack.

The chain of dynamic links is being referred to as dynamic chain if connected in the stack at a given time.

Kindly check the diagram in the attached image below.

8 0
3 years ago
True or false: the HTTPs means that the information on a website has been fact-checked
nevsk [136]

Answer:

False

Explanation:

4 0
3 years ago
Other questions:
  • Write a function get_initials(the name) that takes a string of a name and returns the initials of the name, in upper case, separ
    12·1 answer
  • fill down feature on a formula and you need to keep a cell reference the same which one will allow you to keep the same cell ref
    15·1 answer
  • Me2540 week 5 assignment<br> what do i want to know?
    9·1 answer
  • For this lab you will find the area of an irregularly shaped room with the shape as shown above.
    7·1 answer
  • When a pitcher is holding a baseball, the ball has ______energy.
    9·2 answers
  • ‘The increased availability of mobile digital devices has had a positive impact on how young people use their free time’. Make a
    8·1 answer
  • Pixar is a company that creates a huge amount of images, audio recordings, and videos, and they need to decide what compression
    11·1 answer
  • LAB: Parsing dates in M/D/Y format
    5·1 answer
  • Hey, My paperclips just stoped producing, does anyone have any idea how to start them up again?
    5·1 answer
  • What are the MOST likely reasons that a student would research a topic using the internet?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!