14.4k views
4 votes
Write a function called pyramid(height) that acceptsa parameter ""height"". It then prints a pyramid of that height

User Henriale
by
3.9k points

1 Answer

3 votes

Answer:

I am writing a function in C++

Step-by-step explanation:

C++ program

#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 << '\\'; } } // 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

}

User Steve Harman
by
4.1k points