Yang Hui triangle under java

Source: Internet
Author: User
The Yang Hui triangle under java-general Linux technology-Linux programming and kernel information. The following is a detailed description.

The Yang Hui triangle is a triangle number table arranged by numbers. The general format is as follows:

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

1 6 15 20 15 6 1

........................................ ..............
The most essential feature of the Yang Hui triangle is that its two oblique edges are composed of digits 1, while the remaining number is equal to the sum of the two numbers on its shoulders.

In fact, ancient Chinese mathematicians are far ahead in many important mathematical fields. The history of ancient Chinese Mathematics once had its own brilliant chapter, and the discovery of the Yang Hui triangle was a wonderful page.

Yang Hui, Zi qianguang, from Hangzhou in the Northern Song Dynasty. In his book "detailed explanation of Chapter 9 algorithms" in 1261, the author recorded the triangle number table shown above, which is called the "Origin of the practice.
Such a triangle is also frequently used in our Olympics competition. The simplest thing is to ask you to find a rule. We will explain the specific usage in the teaching content.




Public class YangHui
{
Public static void main (String args [])
{
Final int ROW = 5;
Int a [] [] = new int [ROW + 1] [];
For (int I = 0; I <= ROW; I ++)
{
A= New int [I + 1];
}
Yanghui (a, ROW );
}

Static void yanghui (int a [] [], int ROW)
{
For (int I = 0; I <= ROW; I ++)
For (int j = 0; j <=. Length-1; j ++)
{
If (I = 0 | j = 0 | j =. Length-1)
A[J] = 1;
Else[J] = a [I-1] [J-1] + a [I-1] [j];
}
For (int I = 0; I <= ROW; I ++)
{
For (int j = 0; j <=. Length-1; j ++)
System. out. print ([J] + "");
System. out. println ();
}
}
}



Keywords: 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.