HDU 2032 Yang Hui triangle

Source: Internet
Author: User

HDU 2032 Yang Hui triangle
Yang Hui triangle
Problem Description Do you still remember the Yang Hui triangle I learned in middle school? The specific definition is not described here. You can refer to the following figure:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1

The Input data contains multiple test instances. The Input of each test instance only contains a positive integer n (1 <=n <= 30), indicating the number of layers in the Yang Hui triangle to be output.
Output corresponds to each input. Please Output the Yang Hui triangle of the corresponding layers. Integers of each layer are separated by a space. An empty line is added after each Yang Hui triangle.
Sample Input

2 3

Sample Output
11 111 11 2 1
# Include

 
  
Long YH (int n, int m) {long I = 1, j = 1, s1 = 1, s2 = 1; if (m = 1) return 1; else {m --; n --; for (j = 1; j <= m; j ++) {s1 = s1 * (n --); s2 * = j; if (s1% s2 = 0) // reduce s1 and s2 as early as possible, otherwise {s1/= s2; s2 = 1 ;}} return s1/s2;} int main (void) {long int n; while (scanf (% d, & n )! = EOF) {int I, j; for (I = 1; I <= n; I ++) {for (j = 1; j <= I; j ++) {if (j = 1) printf (% ld, YH (I, j); elseprintf (% ld, YH (I, j);} printf ();} printf ();} return 0 ;}

 


 

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.