注册 登录
编程论坛 C++教室

金字塔问题

zsy142857 发布于 2017-09-09 20:03, 1606 次点击
题目是:输入为一个正整数,一个字符。输出为 3n 行,每行行末不可以有多余空格。
#include<iostream>
using namespace std;
int n;
char c;
void pyramid(int m,char x){
    int i,j;
    for(i=0;i<m;i++){
        for(j=0;j<=m;j++){
        cout<<m-i-1*' ';
        cout<<2*i+1*x;
        cout<<endl;
            }
        }
    }
int main(){   
    cin>>n>>c;   
    pyramid(n,c);
    pyramid(2*n,c);
    return 0;
}
请各位看一看,怎么改才能正确解答(只能改void函数)
4 回复
#2
yangfrancis2017-09-10 09:04
讲规则
#3
yangfrancis2017-09-10 09:40
可能是要这个
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
void pyramid(int num, char ch)
{
    int i,j;
    for(i=0;i<num;i++)
    {
        for(j=0;j<num-i-1;j++)
            cout<<" ";
        for(j=0;j<2*i+1;j++)
            cout<<ch;
        cout<<endl;
    }
}
int main()
{
    int n;char c;
    cin>>n>>c;
    //system("mode con cols=80 lines=80");
    pyramid(n,c);
    return 0;
}
#4
zsy1428572017-09-10 20:30
对不起,不是这个意思
规则是:输入一个正整数n和一个符号(用空格隔开),输出用这个符号组成的高度为n的三角形和高为2n的三角形(共3n行)。
程序:
#include<iostream>
using namespace std;
int n;
char c;
void pyramid(int m,char x){
(只
  能
  在
  这
  改) }
int main(){
cin>>n>>c;
pyramid(n,c);
pyramid(2*n,c);
return 0;
}
 
#5
zsy1428572017-09-13 20:19
不用问了,我已知道
1