等腰三角形
题目描述
输出高度为n的由‘*’组成的等腰三角形,若N<=0,输出“nothing”
输入
一个整数N(0<=N<10^3+100)
输出
由‘*’组成的等腰三角形
样例输入1
3
样例输出1
*
***
*****
样例输入2
5
样例输出1
*
***
*****
*******
*********
废话不多说,上代码。
#include <bits/stdc++.h>//头文件
using namespace std;
int main(void){
int n;
int b,c,d;
cin>>n;
if(n<=0){//错误输入
cout<<"nothing";
return 0;
}
else
for(b=1;b<=n;b++){
for(c=1;c<=n-b;c++)
cout << " ";
for(d=1;d<=2*b-1;d++)
cout << "*";
cout << endl;
}
}
构建等腰三角形:C++代码实现
这篇文章展示了如何使用C++编程语言生成高度为n的等腰三角形,通过控制星号(*)的输出实现。对于错误输入,程序会输出'nothing'。代码示例详细解释了过程。
426

被折叠的 条评论
为什么被折叠?



