title: Program to print Sierpinski triangle
body: <p>i was just looking Wikipedia pages and i found this <a href="http://en.wikipedia.org/wiki/Sierpinski_triangle" rel="nofollow">Sierpinski triangle</a></p>
  
  <p>i want to create this  triangle by <code>java</code>,<code>c</code>,<code>scala</code> etc.</p>
  
  <pre><code>                               1                               
                                111                              
                               11111                             
                              1111111                            
                             111111111                           
                            11111111111                          
                           1111111111111                         
                          111111111111111                        
                         1               1                       
                        111             111                      
                       11111           11111                     
                      1111111         1111111                    
                     111111111       111111111                   
                    11111111111     11111111111                  
                   1111111111111   1111111111111                 
                  111111111111111 111111111111111                
                 1                               1               
                111                             111              
               11111                           11111             
              1111111                         1111111            
             111111111                       111111111           
            11111111111                     11111111111          
           1111111111111                   1111111111111         
          111111111111111                 111111111111111        
         1               1               1               1       
        111             111             111             111      
       11111           11111           11111           11111     
      1111111         1111111         1111111         1111111    
     111111111       111111111       111111111       111111111   
    11111111111     11111111111     11111111111     11111111111  
   1111111111111   1111111111111   1111111111111   1111111111111 
  111111111111111 111111111111111 111111111111111 111111111111111
  </code></pre>
  
  <p>i just create simple program like we create simple pattern in <code>c</code>  i wrote this in <code>scala</code>  </p>
  
  <pre><code>def ft(n: Int) = {
      for (i &lt;- 1 to n) {
        for (j &lt;- n to i by -1) {
          print(" ")
        }
        for (k &lt;- 1 to 2 * i - 1) {
          print("1")
  
        }
        print("\n")
      }
    }
  </code></pre>
  
  <p>to print  this</p>
  
  <pre><code>           1
            111
           11111
          1111111
         111111111
  </code></pre>
  
  <p>and this :</p>
  
  <pre><code>def triangle = {
      for (i &lt;- 1 to 5) {
        for (j &lt;- 1 to 5) {
          if (j &lt;= i)
            print("1")
          else
            print(" ")
        }
        for (j &lt;- 5 to 1 by -1) {
          if (j &lt;= i)
            print("1");
          else
            print(" ");
        }
        print("\n");
      }
    } 
  </code></pre>
  
  <p>how to create this <strong>Sierpinski triangle</strong> ?</p>
  
  <p>just give me idea to solve this ?</p>