C language printing with one-dimensional array Yang Hui triangle (original: accidentally thought)

Source: Internet
Author: User

//Ask for the number of the first 10 rows
1inta[ One] = {1 };2a[0] =1, a[1] =1;3 intI, j,m;4 for(i =2; I <= One; i++)//2-11 output 10 lines5 { 6 for(j = i-1; J >1; j--)//Key in this sentence, backwards beg7 { 8 A[j] = A[j] + a[j-1]; 9printf"%5d", A[j]); Ten } Oneprintf"%5d\n", a[0]); A}

Originally a a[j]=a[j]+a[j-1]

Results found calculation a[j+1], not, think of the inverted to beg, just Yang Hui triangle is also about symmetry, the result output meaning is left and right number upside down, but symmetrical, so feasible

// The key is in this sentence, in reverse, using the symmetry of the Yang Hui Triangle

C language printing with one-dimensional array Yang Hui triangle (original: accidentally thought)

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.