Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram to print Sierpinski triangle
    text
    copied!<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>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload