Here is an example of a MATLAB/Octave script that takes n
as input and prints a pattern using a loop:
main.m187 chars11 lines
In this script, we use a nested for loop where the outer loop runs from 1 to n
and the inner loop runs from 1 to the current value of the outer loop variable. Inside the inner loop, we print an asterisk *
using the fprintf
function. After each inner loop completes, we print a new line using fprintf('\n')
to create the pattern effect.
Please note that this script assumes that the user will enter a positive integer value for n
.
gistlibby LogSnag