Page 253 - CA_Blue( J )_Class9
P. 253
14 j++;
15 }
16 i++;
17 System.out.println();
18 }
19 }
20 }
You will get the following output:
Program 8 Write a program to input number of lines and print the Pascal's Triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 import java.util.*;
2 class for_pascal_triangle
3 { public static void main()
4 { Scanner sc = new Scanner(System.in);
5 int n,sp,i,j,v=1;
6 System.out.print("Input number of rows: ");
7 n = sc.nextInt();
8 for(i=0;i<n;i++)
9 { for(j=0;j<=i;j++)
10 { if (j==0||i==0)
11 v=1;
12 else
13 v=v*(i-j+1)/j;
Nested Loop 251

