write a matlab/octave script that takes n as input and print the following pattern. create a loopp in matlab

Here is an example of a MATLAB/Octave script that takes n as input and prints a pattern using a loop:

main.m
% Prompt the user to enter a value for n
n = input('Enter a value for n: ');

% Loop to print the pattern
for i = 1:n
    for j = 1:i
        fprintf('*');
    end
    fprintf('\n');
end
187 chars
11 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.

related categories

gistlibby LogSnag