Print 10 rows Yang Hui triangle

Source: Internet
Author: User

------------------------------------------------------------------------------------------------------

Print out the Yang Hui Triangle, which can be used as an entrance to thought according to one of its properties: the number of J in line I is equal to the j-1 bit of line i-1 plus the number of j digits, i.e. a[i][j]=a[i-1][j-1]+a[i-1][j].

------------------------------------------------------------------------------------------------------

The C language code is as follows:

# include <stdio.h># include <stdlib.h># include <string.h>int  main () {     int arr[10][10]={{1}};     int  line, row,space;     for  (line = 0; line < 10;  line++)      {          for   (row = 0; row <=line; row++)            {               if   (LINE&NBSP;&LT;&NBSP;2)                              //first two behaviors 1                {                     arr[line][row] = arr[0][0];                }                else if  (row == 0 | |  row == line)         //element is 1                {                     arr[line][row] = arr[0 ][0];               }                else                                        //Use property Assignment                 {                     arr[line][row] =  (arr[line  - 1][row - 1] + arr[line - 1][row]);                }            }     }           for  (line = 0; line < 10; line++)                //Output      {           for  (row = 0; row <= line; row++)           {                printf ("%3d ",  arr[line][row]);           }      printf ("\ n");  }      system (" Pause ");      return 0;}

----------------------------------------------------------------------------------------

little knowledge of dry goods: 1. Right-shift operations with signed values are not portable.

2. The value of the shift operation cannot be negative.

3. The order of evaluation of an expression is partly determined by the precedence and binding of the operators it contains (priority

Greater than the binding); Similarly, the operands of some expressions may need to be converted to other types during evaluation,

("Implicit type Conversions" and "Arithmetic Conversions").

----------------------------------------------------------------------------------------

This article is from the "Nobody" blog, please be sure to keep this source http://814193594.blog.51cto.com/10729329/1702895

Print 10 rows 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.