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
ICE Princess25 [194]
3 years ago
15

Pascal's Triangle is a triangular array in which every number represents the

Computers and Technology
1 answer:
Viefleur [7K]3 years ago
6 0

Answer:

I am writing a JAVA program.

import java.util.Scanner;  // this class is used here to take input from user

import java.util.ArrayList;    // used to create dynamic arrays  

public class PascalTriangle{   // class to print nth line of pascal's triangle

/* function line() that takes the line index (line_no) as parameter and finds the nth line (find line at given index line_no) in the Pascal's Triangle */

   public static ArrayList<Integer> line(int line_no) {  

//declares ArrayList of integers

       ArrayList<Integer> current_line = new ArrayList<Integer>();  

       current_line.add(1);    // sets the element of every line to  1      

/* if conditions checks if the input n-th line is the first line which means it checks if the line to be returned is the 1st one */

       if (line_no == 0) {

       return current_line;  //returns the first line/row}  

/* the following statement produces the previous line by passing the index position (line_no-1) of that line as a parameter of line() method */    

       ArrayList<Integer> previous = line(line_no - 1);    

/* the loop has i variable which is initialized to 1 and this loop continues to execute until the value of i gets greater than or equal to the size of previous line */

       for (int i = 1; i < previous.size(); i++) {  //start of the loop

/* the following statement computes the current line based on the previous line of the Pascal triangle and this is a recursive part. This will compute the elements of the current line based on previous line and store these elements in present*/

           int present = previous.get(i - 1) + previous.get(i);  

//adds the elements computed by the above line to the current_line. this means it adds each element of present to current_line. For example if the n-th  line is 5 then it the elements at 6th row of pascals triangle are found and returned considering the topmost line the "0th" line */

           current_line.add(present); }  

       current_line.add(1);  

     return current_line; } //returns current line i.e. n-th line of pascal triangle  

   public static void main(String[] args)     {  //start of main() function body

      Scanner scan = new Scanner(System.in);  // create Scanner class object

/* prompts user to enter integer n as input to return the nth line of Pascal's triangle */

       System.out.print("Enter·line·of·Pascal's·Triangle·to·print: ");

       int n = scan.nextInt();    //scans and reads the input integer

// calls line function to return the n-th line of Pascal triangle

       ArrayList<Integer> array = line(n);  

       for (int i = 0; i < array.size(); i++) {  /* loop iterates through the array until the loop variable i gets equal to or exceeds the array size in order to display the elements of the n-th line of pascal triangle where n is integer input */

    System.out.print(array.get(i)+ "."); }    }  } //prints the elements of n-th line

/* get() method gets the elements of nth line and . is used to seperate each element with a dot. */

Explanation:

The program is well explained in the comments mentioned with each statement of the program. The program has a function line() that takes as argument the index line_no which is the nth line of Pascal's triangle whose elements are to be displayed. The program computes the line of the previous line number (index) first using recursion. After this the values of the current line is computed with the help of the previous one. This is iterated using a loop until the nth line. In the main() method user is prompted to enter integer n and then line() method is called by passing the n integer to the function to display the elements of this n-th line in pascal's triangle. loop is used to iterate through the entire array and get() method gets the elements of nth line of array and . is used to separate each element with a dot. The program and output is attached in a screenshot.

You might be interested in
Convert the following three hexadecimal numbers to both binary and decimal. (Hint: it is probably easier to convert hex to binar
Doss [256]

Answer:

3e : 00111110 (62)

3e0 : 0000001111100000 (992)

3e00 : 0011111000000000 (15872)

Explanation:

Converting the given hexadecimal numbers to binary and decimal format:

1) 3e

3-> 0011

e-> 1110

Combining , 3e -> 00111110

This can be converted to decimal by multiplying each 1 in the binary representation by 2^(position -1) and adding the results.

So 3e = 32+16+8+4+2 = 62

2) 3e0

Binary => 0000001111100000

Converting to decimal : 992  [ This is 16 times a]

3) 3e00

Binary => 0011111000000000

Converting to decimal : 15872 [ This is 16 times b]

So adding a 0 to the hex representation multiplies the decimal number by 16.

6 0
3 years ago
Which of the following is a proprietary OS for desktop and loptop computers?<br><br>conguardelation
Travka [436]

Answer:

windows

Explanation:

windows is the best operating system for desktop and laptop

3 0
2 years ago
Explain why it is important that software products are developed and delivered quickly. Why is it sometimes sensible to deliver
Mkey [24]

Answer:

The reason why software products are developed and delivered quickly is because  

  • most of the time client cannot wait an extended time for the merchandise to be developed and delivered because the delay in delivery of software products might cause a loss for the client if that specific software is being developed for the client's business solution.  
  • In some mission-critical applications like defense systems, space research systems in such cases software must be delivered as quickly as possible because the project which is getting into such area cannot await an extended time for a software package to be delivered as here time constraint is involved and delay in at some point might cause a loss for an entire ongoing project.

Explanation:

Sometimes sensible to deliver an unfinished product then issue new versions of that product after delivery because

  • Sometimes the software that has got to be developed could be very big which isn't possible to develop during a shorter time and even client cannot wait an extended time for he's software in such case only the primary main core functionality of the software is being developed and delivered to the client and in later version remaining functionality's are included and delivered.

  • Even it is often the case that software that has got to be developed is very complex and should get lots of obstacles during development in such cases also only the core functionalities are being developed and delivered and in later version remaining functionality's are included.

3) Presence of bugs in software may also lead to issue a new version of that software after delivery and then fix the bug and deliver the new version to the client.

5 0
3 years ago
Why are some geo satellites not usually used for transmitting tcp/ip information?
charle [14.2K]
TCP has flow control, which means a two-way connection must be present. Satellites are sometimes optimized for broadcasts, which is unidirectional (ie., sending, not receiving).
6 0
3 years ago
List and explain five instances of issues that pertain to business ethics
castortr0y [4]
Social Media. ...
Harassment and Discrimination. ...
Health and Safety. ...
Technology/Privacy

Disability. ...
Equal Pay. ...
Pregnancy. ...
Race/ Color. ...
Religion. ...
4 0
3 years ago
Other questions:
  • The _________ specifies the station(s) for which the frame is intended. it may be a unique physical address, a group address, or
    5·1 answer
  • A mobile device is freezing almost daily. The device remains powered on and the screen illuminated. The user restarts the device
    8·1 answer
  • WILL GIVE BRAINLIEST TO HELPFUL ANSWERS!
    8·1 answer
  • In 2009 to 2010, 1 in 10 social network users:
    10·1 answer
  • Computer A has an overall CPI of 1.3 and can be run at a clock rate of 600 MHz. Computer B has a CPI of 2.5 and can be run at a
    6·1 answer
  • WILL MARK BRIAN PLZ HELP PLZ I BEG YOU While levels often change in order to give a game some more variability, they might also
    11·1 answer
  • Which of the following is a good conductor of electricity and heat?
    13·2 answers
  • Which of the following is a valid c++ identifier a. mouse b. _int c. 2_stop d. float​
    10·1 answer
  • <img src="https://tex.z-dn.net/?f=%20%5Cfrac%7Bx%7D%7B1%20%2B%20x%7D%20%20%2B%20%20%5Cfrac%7Bx%20%2B%201%7D%7Bx%7D%20%20%3D%20%2
    15·2 answers
  • Outline the dangers arising as a result of using computers​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!