Showing posts with label Pyramid. Show all posts
Showing posts with label Pyramid. Show all posts

Friday, August 10, 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");
       }
}
}

Pyramid Program 3


Pyramid Program 3
 Output
----------
 1
 1 2
 1 2 3
 1 2 3 4
 1 2 3 4 5
 1 2 3 4
 1 2 3
 1 2
 1
Pyramid Program 3
Source code
-------------
package com.swain.cell;

public class Piramid3 {

       public static void main(String args[]){
              int i,j;
              for(i=1;i<=5;i++)
              {
              for(j=1;j<=i;j++)
              System.out.print(" "+j);
              System.out.print("\n");
              }
              for(i=4;i>=1;i--)
              {
              for(j=1;j<=i;j++)
              System.out.print(" "+j);
              System.out.print("\n");
              }
       }
}

Pyramid Program 2


Pyramid Program 2
 Output
----------
 1
 1 2
 1 2 3
 1 2 3 4
Pyramid Program 2
Source code
-------------
package com.swain.cell;

public class Piramid2 {

       public static void main(String args[]){
       int i,j;
       for(i=1;i<=4;i++)
       {
       for(j=1;j<=i;j++)
       System.out.print(" "+j);
       System.out.print("\n");
       }
       }
}

Pyramid Program


Pyramid Program 1
 Output
----------
    *
   * *
  * * *
 * * * *
* * * * *

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

public class Piramid {

       public static void main(String args[]){
              int p=1;
              for(int i=1;i<=5;i++){
                     for(int j=i;j<5;j++){
                           System.out.print(" ");
                     }
                     for(int k=1;k<=p;k++){
                           if(k%2==0){
                                  System.out.print(" ");

                           }else
                           System.out.print("*");

                     }
                     System.out.println();
                     p+=2;
              }
       }
}

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...