IOS-print the waist of the Yang Hui triangle

Source: Internet
Author: User

 

 

Prerequisite: the number of endpoints is 1.
1. Each number is equal to the sum of the two numbers above it.
2. Each line of numbers is symmetric between the left and right, and gradually increases from 1.
3. There are n numbers in the nth row.
4. The number in line n is 2 ^ (n-1 ).
5. The number of m in row n is equal to the number of n-m + 1, that is, C (n-1, m-1) = C (n-1, n-m), which is a combination of numbers.
Formula of Property 6
One
6. Each number is equal to the sum of the left and right numbers in the previous row. The entire Yang Hui triangle can be written in this way. That is, the number of I in the n + 1 row is equal to the sum of the number of I-1 in the n row and the number of I, which is also one of the properties of the combination number. (For the formula, see the picture on the right)

 

 


Int n;

Scanf ("% d", & n );


Int I, j, k, a [n] [n]; // I control row, j control column


For (I = 0; I <n; I ++ ){

A [I] [0] = 1; a [I] [I] = 1; // The first and last rows are 1

}



For (I = 2; I <n; I ++ ){


For (j = 1; j <= I-1; j ++ ){



A [I] [j] = a [I-1] [j] + a [I-1] [J-1]; // equals the sum

}


}

// Print the Yang Hui triangle of the waist below

For (I = 0; I <n; I ++ ){


// K control space

For (k = 0; k <n-1-i; k ++ ){


Printf ("");


}

For (j = 0; j <= I; j ++ ){


Printf ("% 6d", a [I] [j]);


}

Printf ("\ n ");

}

 

 

 

 

Input: 10

Print:

 
 

 

 

 


---

 

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.