Computer Science
Solve w/ while loop
100 feet of fencing
Should be a post every 10 feet
How many posts do you need?
Post= 0;
Fence=0;
While Fence ≤ 100
Post=Post+1;
Fence=Fence +10;
Disp(Post)
Using the while loop construct, create a program that generates a random integer from 1 to 10 and prompt user to repeatedlt make attempts to guess the number. The program should continue to prompt for guesses until the user makes the correct one, at which point the program should congratulate the user and reveal the random number.

X=ceil(rand()*9+1);
Guess=input(‘Guess the number);
While guess~=x
Guess=input(‘Wrong, Try again);
Disp(‘Correct”);
FOR LOOP
A picket fence can be described by two arrays. Each array has five entries representing the five fence posts. The first array, Heights, describes the height of each fence post. The second array, Locations, describes the distance of each fence post from the first one. Working together as a group, create two separate MATLAB functions for dealing with a picket fence. The first MATLAB function should find the highest fence post. The second MATLAB function should find the smallest distance between fence posts. Save the functions in m-files “fp1” and “fp2” followed by the first and last initials of all group members.

Height=[5,6,4.5,5.5,7];
Locations = [0,4,10,13,20];
Function [result]=fp1(heights)
Result=heights(1);
For i=2:length(heights)
If heights(i)>result
Result=heights(i);
Function[result]=fp2(locations);
Result=locations(2)-Locations(1);
For i=3:length(locations)
If (locations(i) – locations(i-1))

Get Your Essay

Cite this page

Separate Matlab Functions And First Array. (July 4, 2021). Retrieved from https://www.freeessays.education/separate-matlab-functions-and-first-array-essay/