php_js_css_html--Yang Hui Triangle

Source: Internet
Author: User


<?php

function Yanghui ($lines) {
Echo ' ;//Header insert CSS style
Echo ' <a id=cow> ', $lines, ' </a>';
Echo ' <a id=column> ', ($lines-$lines%2)/2 + ($lines%2), ' </a>‘;//Want to set each table to conform to the same width,
//to get the width of a number that has the largest value
//here we get the position of this number first.。
//Use JS code to get its width, CSS set td width
Echo ' <table > ';//A table put a number
for ($i =1; $i <= $lines; + + $i) {
Echo ' <tr> ';
for ($x =1; $x <= $lines-$i; + + $x)the values of the//Yang Hui triangle have n rows n columns the first number at the top already has a 1
{echo ' <td>&nbsp</td> ';}//Isosceles triangle to consider the number of spaces left in 1, so here is the $lines-$i;
for ($j =1; $j <= $i; + + $j) {

Echo ' <td id= ', $i, $j, ' > ';id= "11" 1 rows and 1 columns per table, changing with loops

//First column, diagonal
if ($j ==1 | | $j = = $i)
{
Echo$data [$i] [$j] = 1;//Assign value first, then output
}
Else
{
Echo$data [$i] [$j] = $data [$i -1][$j] + $data [$i -1][$j-1];//The value of each number is the sum of two numbers above that number

}
Echo ' </td> ', ' <td>&nbsp</td> ';//One space at a time per cycle
}

Echo ' </tr> ';
}
Echo ' </table> ';
Echo
' <script type= ' text/javascript ' >
var cow = document.getElementById ("cow"). InnerHTML
var column = document.getElementById ("column"). InnerHTML

var td = document.getElementById (Cow+column)
var width_td = td.offsetwidth
var HD = document.getElementById ("HD")
var stl = document.createelement ("style")
stl.innerhtml = "A{visibility:hidden;} td {Width: "+ width_td +" Px;text-align:center;color:green;} "
Hd.appendchild (STL)
</script> ';
}

Yanghui (a);



php_js_css_html--Yang Hui Triangle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.