nt a Mayo pyramid with # characters depending on user input, i.e., the pyramid height h. To this end, update the size of the array for each level of the pyramid (for each for loop passing) using the realloc function. First of all, allocate an array for the first row. You need the allocate the memory for h + 2 characters for the first row. Fill it with spaces,
Language: C
Print a Mayo pyramid with # characters depending on user input, i.e., the pyramid height h. To this end, update the size of the array for each level of the pyramid (for each for loop passing) using the realloc function. First of all, allocate an array for the first row. You need the allocate the memory for h + 2 characters for the first row. Fill it with spaces, using the memset(row, ’ ’, h+2) command. For each row i, expand the array size to h + 4 + i, replace the last two characters of the line with # sign, followed by the string’s null terminator. That’s why you need increase the size by 2, with the respect to the original allocation, and then by 1 at each step. You also need to replace the space at the position h − 1 − i with the # character (the left slope of the pyramid). Print and examine your results, free the memory and use the valgrind function to check memory usage.
![Print a Mayo pyramid with # characters depending on user input, i.e., the pyramid height h.
To this end, update the size of the array for each level of the pyramid (for each for loop passing)
using the realloc function. First of all, allocate an array for the first row. You need the allocate
the memory for h+2 characters for the first row. Fill it with spaces, using the memset (row, '',
h+2) command. For each row i, expand the array size to h+4+i, replace the last two characters
of the line with #sign, followed by the string's null terminator. That's why you need increase the
size by 2, with the respect to the original allocation, and then by 1 at each step. You also need
to replace the space at the position h - 1 - i with the # character (the left slope of the pyramid).
Print and examine your results, free the memory and use the valgrind function to check memory
usage.
##
###
1
#
##
###](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa189e731-9824-45eb-b60d-554e8b785106%2Ffa9e50fe-cea0-4aba-b30a-64b88524155b%2Ffozpagk_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)