关于c++的问题,如何解决?

#c++

img


#各位朋友们 这个三角形用c+ 应该怎么编 需要用的for循环编完总是出错


#include <iostream>
using namespace std;
 
int main()
{
    int space, rows;
 
    cout <<"输入行数: ";
    cin >> rows;
 
    for(int i = 1, k = 0; i <= rows; ++i, k = 0)
    {
        for(space = 1; space <= rows-i; ++space)
        {
            cout <<"  ";
        }
 
        while(k != 2*i-1)
        {
            cout << "* ";
            ++k;
        }
        cout << endl;
    }    
    return 0;
}

#include"stdio.h"
main(){
    int h,l;
    
    for(h=1;h<=5;h++){
        
        for(l=5;l>=h;l--){
            printf(" "); 
        }
        
        for(l=1;l<=2*h-1;l++){
            printf("*"); 
        }
        printf("\n"); 
    }
}