C language on the screen output Yang Hui's triangle _c language

Source: Internet
Author: User

This is the Yang Hui's triangle, also known as Jia Xiansan. This is the most closely related to our current study is the coefficient rule of the 2-term powers expansion. As shown in Jia Xiansan, the third number in line 3rd corresponds to the two number and the square formula in turn.
The Yang Hui's triangle is a number of triangular tables of numbers, in general form as follows:

.................................................

The rule of the Yang Hui's triangle is that its two hypotenuse is made up of the number 1, while the rest is equal to the sum of two digits on its shoulders.
The code is as follows:

#include <stdio.h>
#include <stdlib.h>
 
int main ()
{
 int i,j,k,arr[10][10]={0};/*arr[11 ][11] must be initialized, initialized to {0}*/
 printf ("Print out Yang Hui's triangle: \ n");
 for (i=0;i<10;i++)
 {/* First print out the first column and diagonal number, both 1, and the 12th line has been printed * *
  arr[i][0]=1;
  arr[i][i]=1;
 }
 for (i=2;i<10;i++)
 {/* The Yang Hui's triangle arrangement is analyzed by the rule * * for
  (j=1;j<10;j++)
  {
   arr[i][j]=arr[i-1][j-1]+arr[ I-1][J];
  }
 for (i=0;i<10;i++)
 {for
  (k=0;k<10-i;k++)
  {
   printf ("");
  }
  for (j=0;j<=i;j++)
  {
   printf ("%d", arr[i][j]);
  printf ("\ n");
 }
 System ("pause");
 return 0;
}

I hope this article is helpful to the learning of C program algorithm design.

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.