翻转金字塔
第二个解法有问题
求大佬指点
题目描述
KiKi学习了循环,BoBo老师给他出了一系列打印图案的练习,该任务是打印用“”组成的翻转金字塔图案。
输入描述:
多组输入,一个整数(2~20),表示翻转金字塔边的长度,即“”的数量,也表示输出行数。
输出描述:
针对每行输入,输出用“”组成的金字塔,每个“”后面有一个空格。
示例1
输入
5
输出
* * * * *
* * * *
* * *
* *
*
下面这个成功OJ
#include<iostream>
using namespace std;
int main(){
int n;
while(cin>>n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<i;j++)
{
cout<<" ";
}
for(int j=n;j>i;j--)
{
cout<<"* ";
}
cout<<endl;
}
}
}
下面这个为什么OJ
救救孩子
题目转送门
https://www.nowcoder.com/practice/8b935f8ffe99445dbd42494febd13e45?tpId=107&tags=&title=&diffculty=0&judgeStatus=0&rp=1&tab=answerKey
#include<iostream>
using namespace std;
int main ()
{
int a;
while(cin>>a)
{
for(int i=1;i<=a;i++) //控制行数
{
for(int j=a;j>=i;j--)
cout<<"* ";
cout<<endl;
for(int k=1;k<=i;k++)
cout<<" ";
}
cout<<endl;
}
}