Saturday, 1 September 2012

Pyramid Program 4


Pyramid Program 4
 Output
----------
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1

Pyramid Program 4
Source code
-------------
package com.swain.cell;

public class Piramid4 {

       public static void main(String args[]){
       int i,k,j;
       for(i=1;i<=200;i= i*2){

              for(j=1; j<=i; j=j*2)
              System.out.print(j + " ");

              for(k=i/2; k>=1; k=k/2)
              System.out.print( k + " ");
              System.out.print("\n");
       }
}
}

No comments:

Post a Comment