Output the Yang Hui triangle in the lower left triangle.

Source: Internet
Author: User
Tags printf

Description

Output the Yang Hui triangle in the lower left triangle.

Input

Enter a positive integer n (n≤10).

Output

Outputs n rows Yang hui triangles. Each number has a width of 4.

"Input Sample"

5

"Output Sample"

1

1 1

1 2 1

1 3 3 1

1 4 6) 4 1

Prompted

Output the Yang Hui triangle in the form of the lower left triangle, using the main diagonal as the dividing line between 0 elements and non-0 elements. Suppose I and J represent the row and column subscripts of a two-dimensional array, respectively.

The elements on the ① triangle two waist are 1. Two waist one for the No. 0 column, one for the main diagonal.

② the remaining elements of the triangle are equal to the sum of the two shoulder elements (the sum of the previous column element and the same column element on the previous row) except for the two waists.

Source

"The basis of program design--take C as an example," the 6th chapter on the computer experimental question 8.




#include <stdio.h>

	int main () {
	
		int n,i,j,a[10][10];//first became a[10], so the subscripted value is neither array nor pointer nor vector errors
							//Hints I subscript error 
		scanf ("%d", &n);
		for (i=0;i<n;i++) {for
			(j=0;j<n;j++) {
				if (j==0| | I==J)
					a[i][j]=1;
				else{
					a[i][j]=a[i-1][j]+a[i-1][j-1];}}
		}
			for (i=0;i<n;i++) {
			for (j=0;j<n;j++) {
				if (i>=j)
					printf ("%4d", A[i][j]);//Enter Forgot to add 
				
			}
				printf ("\ n");}
	}


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.