(Algorithm practice) - the number of columns

Requirements:
http://codeup.cn/problem.php?cid=100000583&pid=1
Description:
This question actually spent a lot of time on how to output triangle. . . = = Not easy, these graphics routines necessary to sum up. . It is not difficult to understand
the code:

#include <stdio.h>
#include <string.h>
int F(int a){
	if(a == 0 ){	
		return 0;	
	} 
	else if(a == 1 ||a == 2){	
		return 1; 
	} 
	else{	
		return F(a - 1) + F(a - 2);	
	}
}

int main(){
	int n,m;
	int signal = 0;
	int record[100];
	while(scanf("%d",&n) != EOF){
		for(int i = 0;i <n;i++){
			scanf("%d",&m);
			for(int j = 0;j <m*2 - 1;j++){
				record[signal++] = F(j);
			}
			for(int t = 0;t <m;t++){
				for(int s = 2*t + 1;s <=(m-1)*2;s++){
					printf(" ");
				}
				for(int p= 0;p <2*t + 1;p++){
					printf("%d ",record[p]);
				}
				printf("\n");
			}
			//务必重置,不然会把数组占满报错!!
			memset(record,0,sizeof(record));
			signal = 0;
			
		}
	}
}
Published 105 original articles · won praise 3 · Views 1965

Guess you like

Origin blog.csdn.net/weixin_42377217/article/details/103995463