MATLAB QUESTION In mathematics Pascals triangle is a triangu
MATLAB QUESTION
In mathematics, Pascal\'s triangle is a triangular array of the binomial coefficients. Each row begins and ends with the number one. The remaining numbers are obtained by summing the two numbers that lie directly above that number on the previous row and the number that it follows. So, in order to find the numbers in the nth row of the triangle, we need the values of the (n - 1) the row. Let\'s say that we have computed the fourth row 13 3 1. Now, the fifth row has five elements. The first and the last element would be one. The remaining elements would be (1 + 3), (3 + 3), (3 + 1) = 4, 6, 4. So, the complete fifth row would be 1 4 6 4 1. Here is an example: Use inputdlg() function to ask user how many rows should be displayed. Assign this value to a variable N. (You might use inputdlg() and str2num() commands together.) Create an N by N 2D array of all zeros. Use loop statements to generate a Pascal\'s triangle based on that all zeros 2D array. You might use 0 to represent the empty spot in the Pascal\'s triangle. Then, display your 2D array. For example, if the user input is N = 4, the Pascal\'s triangle you generated should be like this:Solution
public class Pascal {
public static void main(String args[])
{
int r, i, k, number=1, j;
r = 4;
for(i=0;i<r;i++)
{
number = 1;
for(j=0;j<=i;j++)
{
System.out.print(number+ \" \");
number = number * (i - j) / (j + 1);
}
for(;j<r;j++)
{
System.out.print(0+ \" \");
}
System.out.println();
}
}
}

