递归三角形

#include<bits/stdc++.h>
using namespace std;
int s=0;
bool b=0;
void f(int n,int x){
	if(x==0){
		return;
	}
	for(int i=1;i<x+1;i++){
		cout<<i<<" ";
	}
	cout<<endl;
	if(x>=n||b==1){
		b=1;
		f(n,x-1);
	}else{
		f(n,x+1);
	}
}
int main(){
	int n;
	cin>>n;
	f(n,1);
	return 0;
}

  

posted @ 2025-07-24 09:29  陈若麟  阅读(9)  评论(0)    收藏  举报