Pascal Triangle In a previous assignment, you have been asked to evaluate severa
ID: 3548325 • Letter: P
Question
Pascal Triangle
In a previous assignment, you have been asked to evaluate several Java programs for generating a Pascal triangle, posted on the Internet.
Write a program that computes the combination of n things taken r at a time. User input is n and r.
Note that the number of combinations of a group of n objects taken r at a time is:
Next write a combination and permutation calculator. The user inputs n and r; the user interface should be a GUI. Use chapter 4 as examples. There should be a textbox for inputting n and one for r, another textbox for outputting the result and a push button with the legend
C(n, r) = n ! / r! (n - r)! P(n, r) = nPr = nPr = n! / (n - r)!Explanation / Answer
both A and D :
For A, give input as "6"
and for D specify any input ..
Pascal tringle with loops is as follows
import java.io.*;
import java.lang.*;
class PascalTriangle {
public static void main(String[] args) {
String inpstring = "";
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
try
{
System.out.print("Enter number of rows for pascal triangle:");
inpstring = reader.readLine();
int n = Integer.parseInt(inpstring, 10);
for (int y = 0; y < n; y++)
{
int c = 1;
for(int q = 0; q < n - y; q++)
{
System.out.print(" ");
}
for(int x = 0; x <= y; x++)
{
System.out.print(" ");
System.out.print(c); // 3 digits
System.out.print(" ");
c = c * (y - x) / (x + 1);
}
System.out.println();
System.out.println();
}
System.out.println();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}