Here is a MATLAB/Octave script that takes 7 as input and prints the specified pattern:
main.m282 chars19 lines
When you run the above script, it will output the following pattern:
main.m50 chars2 lines
In the script, we use nested for loops to print the pattern. The outer loop controls the number of lines in the pattern, and the inner loop controls the numbers to be printed on each line. We start by printing the numbers in descending order from i
to 1, then we move to the next line and print the numbers in ascending order from 1 to i-1
. Finally, we print a single 1 to complete the pattern.
gistlibby LogSnag