正经题解|本题第一条
2026-07-09 18:36:33
发布于:广东
8阅读
0回复
0点赞
此题有两种解法( ̄︶ ̄)↗
方法一:
#include<bits/stdc++.h>//每日万能头文件
using namespace std;
int main(){
int n;cin>>n;
for(int i=1;i<=n;i++){//输出n层
for(int j=1;j<=i-1;j++){//从第二遍开始才有空格
cout<<" ";
}
for(int j=1;j<=n+1-i;j++){//星号输出
cout<<"*";
}
cout<<endl;
}
return 0;//return 0好习惯
}
方法二:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
for(int i=n;i>0;i--){//条件变了
for(int j=1;j<=n-i;j++){
cout<<" ";
}
for(int j=1;j<=i;j++){//还有这
cout<<"*";
}
cout<<endl;//别忘了换行
}
return 0;//好习惯
}
🎉🎉🎉🎉彦祖亦菲们一键三连🎉🎉🎉🎉
这里空空如也







有帮助,赞一个