Back

Pattern 33

C
            #include<stdio.h>
              #include<conio.h>
              void main(){
                int i, j;
                clrscr();
                for(i=1;i<6;i++){
                   printf("\n");
                   for(j=5-i;j>0;j--){
                printf("  ");
                   }
                   for(j=i;j>=1;j--){
                printf(" %d  ",i);
                   }
                }
                getch();
             }
          
Output:
                     1
                   2   2
                 3   3   3
               4   4   4   4
             5   5   5   5   5
          
Download Program
Java
            public class Pgm33 {
              public static void main(String[] args) {
                // TODO Auto-generated method stub
                for(int i=1;i<6;i++){
                      System.out.print("\n");
                      for(int j=5-i;j>0;j--){
                  System.out.print("  ");
                      }
                      for(int j=i;j>=1;j--){
                  System.out.print(" "+i+"  ");
                      }
                  }
              }
            }
          
Output:
                     1
                   2   2
                 3   3   3
               4   4   4   4
             5   5   5   5   5
          
Download Program
C++
            #include<iostream>
            using namespace std;
            int main(){
              int i, j;
              for(i=1;i<6;i++){
                 cout<<"\n";
               for(j=5-i;j>0;j--){
                 cout<<"  ";
               }
               for(j=i;j>0;j--){
                 cout<<" "<<i<<"  ";
               }
              }
             getc;
             return 0;
            }
          
Output:
                     1
                   2   2
                 3   3   3
               4   4   4   4
             5   5   5   5   5
          
Download Program