Pascal Triangle Pascal Triangle Yang Hui triangle two-term theorem

Source: Internet
Author: User

Pascal Triangle







Wait a while, and then pull Pascal triangle~.

First a year ago to print Yang Hui triangle method paste out (simply do not recognize the look, more and more afraid to see their own writing)


C Language implementation:

/*************************************************************** Code writer:eof Code date:2013.05.16 e-mail: [Email protected] Code Description:here is a demo-to-print out the Pascal triangle.******************************************* /#include <stdio.h> #include <stdlib.h>void buildup (int s, int *n), void putout (int s,    int *n); int main () {int row = 0;    int k = 0, m = 0, x = 0, S = 0;    printf ("Please enter the row number");         while (!SCANF ("%d", &s)) {while (GetChar ()! = ' \ n ');    printf ("Please enter again!\n");    } int *n = (int *) malloc ((S + 1) * (S/2) *sizeof (int));        if (!n) {printf ("malloc failed!\n");    return-1;    } buildup (S, n);    Putout (S, N); return 0;}    void buildup (int S, int *n) {int row, K, m, X, Y, a, B;        row = k = m = x = y = a = b = 0;    Initialization for (m = 0; m < (s+1) * (S/2); m++) {n[m] = 0; } for (row = 1; row &Lt;= S;        row++) {m = ((row* (row-1))/2);    N[M] = 1;        } for (row = 1;row <= S; row++) {m = ((row* (row+1))/2)-1;    N[M] = 1;            }//key method for (k = 2, K <= S-1; k++) {for (row = (3 + k-2); row <= S; row++) {            m = ((row* (row-1))/2)-1 + k;            x = M-row;            y = m-row + 1;            A = ((row* (row+1))/2)-row;            B = ((row* (row+1))/2)-1;            if (M! = a && m! = b) {N[m] = N[x] + n[y];            } else {n[m] = 1;    }}}}void putout (int S, int *n) {int row, blank, rank, num;    row = blank = Rank = num = 0; for (row = 1, row <= S; row++) {if (row = = 1) {for (blank = 1; blank <= (s-row); blank+            +) {printf ("");      }} else {for (blank = 1; blank <= (S-row); blank++)      {printf ("");            }} for (rank = 1; rank <= row; rank++) {printf ("%d", N[num]);            num++;            if (rank = = row) {printf ("\ n");        } printf (""); }    }}










Photo taken on August 14, 2014




Pascal Triangle Pascal Triangle Yang Hui triangle two-term theorem

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.