Answer:
I am writing a function in C++
Explanation:
<h2>C++ program</h2>
#include <iostream>
using namespace std;
int pyramid(int height) // function pyramid with parameter height
{int distance; //variable for spaces
for(int i = 1, j = 0; i <= height; ++i, j= 0) //handle the rows
{
for(distance= 1; distance<= height-i; ++distance)
// handles the spaces & columns
{ cout <<" "; } //prints spaces between stars
while(j!= 2*i-1) //handles shape and spaces
{ cout << "* "; // printing stars
++j; }
cout << '\n'; } } // for the next line
int main()
{
int height; //declare height variable
cout <<"Enter height of pyramid "; //asks user to enter height of pyramid
cin>>height; //stores value of height
pyramid(height); //calls pyramid function
}