Question

In: Computer Science

In Matlab , Write a script that will print a side-ways triangle pattern of stars in...

In Matlab , Write a script that will print a side-ways triangle pattern of stars in

the command window. The script should ask the user how many stars will be

between the center of the triangle at the base and the tip of the

triangle

Solutions

Expert Solution

Here according to the question, side-ways triangle pattern of stars with center of base is not getting very much clear. So here two patterns of triangles are given with full programming code, as Pattern 1 and Pattern 2.

Pattern: 1

prompt='How many stars between center of base to tip of the triangle:';
n=input(prompt);
fprintf('Side-ways triangle pattern of stars is as below\n');
for i = 1:n
for j = 1:i
fprintf('*');
end
fprintf('\n');
end

Pattern:2

prompt='How many stars between center of base to tip of the triangle:';
n=input(prompt);
k=0;
fprintf('Side-ways triangle pattern of stars is as below\n');
for i = 1:n
for j = 1:n-i
fprintf(' ');
end
for k=0:(2*i-1)-1
fprintf('*');
k=k+1;
end
k=0;
fprintf('\n');
end



Related Solutions

the language is matlab 1) Write a code that will print a list consisting of “triangle,”...
the language is matlab 1) Write a code that will print a list consisting of “triangle,” “circle,” and “square.” It prompts the user to choose one, and then prompts the user for the appropriate quantities (e.g., the radius of the circle) and then prints its area. If the user enters an invalid choice, the script simply prints an error message. For calculating the area, create separate functions for each choice. Name them as calcTriangle, calcCircle, calcSquare respectively, which are only...
MATLAB please make it simple to understand P4.2.5 Write a script that draws an equilateral triangle...
MATLAB please make it simple to understand P4.2.5 Write a script that draws an equilateral triangle that is partitioned into four smaller equilateral triangles by connecting the midpoints of its sides. The four little triangles should be colored differently.
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
Write a python code which prints triangle of stars using a loop ( for loop )...
Write a python code which prints triangle of stars using a loop ( for loop ) Remember what 5 * "*" does The number of lines of output should be determined by the user. For example, if the user enters 3, your output should be: * ** *** If the user enters 6, the output should be: * ** *** **** ***** ****** You do NOT need to check for valid input in this program. You may assume the user...
Write a program that prompts the user for the length of one side of a triangle...
Write a program that prompts the user for the length of one side of a triangle and the sizes of the two adjacent angles in degrees and then displays the length of the two other sides and the size of the third angle.
write a matlab script for double mass spring system with animation.
write a matlab script for double mass spring system with animation.
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as...
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as well as the tank dimensions in feet. Assume that the initial measurements are 7 meters in diameter and 11 meters tall. Display your final answers to the screen using disp and a statement without a semicolon, e.g. write the following into your script disp(‘The capacity in U.S. gallons is:’), capacity, where capacity is a variable that you defined in preceding calculations. Part B: In...
• In this script, write MATLAB code to create an array A of size 100 ×...
• In this script, write MATLAB code to create an array A of size 100 × 3. The first column should contain random numbers between 0 and 10. The second column should also contain random numbers between 0 and 10. The third column should contain random integers between 20 and 50. The first two columns represent the x and y coordinates of a map, respectively. The third column represents the height of buildings. For example, if the first row of...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this new matrix to a file called “Assignment3_Question5.dat”.
Write as a script in the editor window of Matlab: Concession stand. Write a program, ConcessionStand.m,...
Write as a script in the editor window of Matlab: Concession stand. Write a program, ConcessionStand.m, that uses vector-matrix multiplication to tabulate and display the cost of each of the following orders. Assume that a hot dog costs $3.00, a brat costs $3.50, and a Coke costs $2.50. ----------------------------------------------------   hot dogs brats cokes order 1    2 1 3 order 2 1 0 2 order 3 2 2 2 order 4 0 5 1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT