Question: Please do the following Matlab problem, Write a function to print an array of stars to the screen in the form of an isosceles triangle.
Please do the following Matlab problem,
Write a function to print an array of stars to the screen in the form of an isosceles triangle. The function will have one input and no outputs. The input will be the number of stars in the base of the triangle. Heres an example of what the output would look like for an input value of 9:
*
***
*****
*******
*********
Since the input value must be an odd number, include a test at the beginning of the function to check that the input is odd. One way to do this is to use the built-in MATLAB mod function. The mod function returns the remainder when dividing one integer by another. For example, mod(6,2) = 0, since the remainder is zero when dividing 6 by 2. mod(7,2) = 1, since dividing 7 by 2 results in a remainder of 1.
Hint: use nested loops. The outer loop will be over the rows, and the inner loop over the columns. The indices of the inner loop will be a function of the row number
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
