Triangle right angle (C)

Triangle right angle


#include<stdio.h>
#define N 10
int main()
{
	int i,j,a[N][N];
	for(i=0;i<N;i++)
		a[i][i]=a[i][0]=1;
		
	for(i=2;i<N;i++)
		for(j=1;j<i;j++)
			a[i][j]=a[i-1][j]+a[i-1][j-1];
	
	//输出		
	for(i=0;i<N;i++){
		for(j=0;j<=i;j++)
			printf("%-10d",a[i][j]);
		printf("\n");		
	}
	return 0;
 } 
  1. The first column is 1
  2. The row number is equal to the column number 1 is also
  3. In addition: the one below is actually the sum of its two heads

Triangle right angles, stored in a two-dimensional array, its regularity

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

Corresponding to the index:

0,0
1,0 1,1
2,0 2,1 2,2
3,0 3,1 3,2 3,3
4,0 4,1 4,2 4,3 4,4

If you still feel right angle Triangle myself some difficult, difficult to understand, you can look at the following simple for loop problems, to find the feeling

  • Output symbol C
    is typically in the book, the subject is a stepping stone for loop
#include<stdio.h>
int main()
{
	printf("***\n");
	printf("*\n");
	printf("*\n");
	printf("***\n");
	return;
}
  • Output nine-by-nine formulas
    understanding of the double for the cycle
#include<stdio.h>
int main()
{
	int i, j;
	for(i = 1; i < 10; i++){
		for(j = 1 ;j < 10; j++){
			printf("%d * %d = %-4d", i, j, i*j);
		}
	printf("\n");	
	}
	return 0;
 } 
  • Print triangle with a left loop
    start loop for flexible use
#include<stdio.h>
int main()
{
	int i,n;
	for(i = 1; i <= 7; i += 2){
		for(n = 1; n <= i; n++){
			printf("* ");
		} 
		printf("\n");
	}
	for(i = 5; i >= 1; i -= 2){
		for(n = 1; n <= i; n++){
			printf("* ");
		} 
		printf("\n");
	}
	return 0;
 } 
Published 150 original articles · won praise 267 · Views 150,000 +

Guess you like

Origin blog.csdn.net/Zhangguohao666/article/details/88900260