In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
I would like to share with you how to print Yang Hui triangles in C language. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it!
1. Topic description
Yang Hui triangle
Before we solve the problem, let's find out what the Yang Hui triangle is.
Yang Hui triangle, also known as Pascal triangle, Jiaxian triangle, Haiam triangle, its arrangement is like a triangle.
Because it first appeared in the Southern Song Dynasty Yang Hui's "detailed interpretation of the Nine chapters algorithm" got its name, and Yang Hui's explanation in the book is quoted from Jia Xian's "release lock calculation book", so it is also called Jia Xian triangle.
The ancient Persian mathematician Omar Hayam also described the triangle. In Europe, it is also known as the Pascal triangle (Pascal's triangle) because the French mathematician Blaize Pascal first fully discussed this triangle in his 1653 on arithmetic Triangle.
The first 10 lines of Yang Hui's triangle are written as follows
two。 Problem-solving ideas
In fact, the rule is very simple. Let's take a look.
Write the number 1 in the middle of the top line
The second line, write down two 1s, and the previous line form a triangle
Each subsequent line, the beginning and the last number is 1, and every other number is the sum of its upper left and upper right numbers, that is, except for the leftmost and rightmost numbers in each row, each number is equal to the sum of its upper left and upper right numbers.
3. Moving picture demonstration
4. Code implementation
We can draw the following conclusions from the moving picture.
1. There are numbers 1 on both sides
2. Starting from the third line, all the numbers except the number 1 on both sides are added by the number on the shoulder.
For friends who are not familiar with the algorithm, it may be more difficult to print directly, so we might as well take a few steps to do it.
Step1
1. Define a two-dimensional integer array with 9 rows and 9 columns
2. All elements of the array are assigned to 1
3. Output all elements of the array
# include int main () {/ / defines a two-dimensional integer array of nine rows and nine columns int data [9] [9]; int I = 0; int j = 0; for (I = 0; I < 9; iDiffect +) {for (j = 0; j < 9; Jake +) {/ / all elements of the array are assigned to 1 data [I] [j] = 1 }} / / output all elements of the array for (I = 0; I < 9; iTunes +) {for (j = 0; j < 9; data +) {printf ("% 6d", data [I] [j]);} printf ("\ n");} return 0;}
Let's take a look at the output.
But all we need is the number in the lower left corner.
So modify the second for loop so that j
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.