Tuesday, 1 March 2016

Types of pyramid programs pattern 16


Program
class Main{
public static void main(String args[]){
int i,j,k=1;
for(i=0;i<=5;i++){
for(j=1;j<=5-i;j++)
System.out.print(" ");
for(j=0;j<=i;j++){
if(j==0||i==0)
k=1;
else
k=(k*(i-j+1)/j);
System.out.print(" "+k);
}
System.out.println(" ");
}
}
}


OUTPUT:-
C:\Users\Saty\Desktop\java>javac 1.java
C:\Users\Saty\Desktop\java>java Main
      1
     1 1
    1 2 1
   1 3 3 1
  1 4 6 4 1
 1 5 10 10 5 1

No comments:

Post a Comment