Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will create a program that accepts as input an array of values as well as a

ID: 3701040 • Letter: Y

Question

You will create a program that accepts as input an array of values as well as a search value, and the output of the program will be the index number and the value of the array entry that is the closest to the array. You may only use "for", "while", "if", "elseif", and "size" commands; you may not use max, min, find, or other commands unless explicitly approved First, develop your pseudocode. For this assignment, you must include your pseudocode at the top of your .m file code. Your code will run somewhat like this: >>[value, index) = ME3430-Activity|0(array,search-value)

Explanation / Answer

function search(array, search value)

BEGIN

index = -1;

for i = 1 to length(array)

BEGIN

      if array(i) is the required element search_value

       BEGIN

      index = i;

   break out of loop

end

end

return index;

end

function [value, index] = SE3120_Activity6(array, search_value)

    value = search_value;

   index = -1 if element is not found

    index = -1;

   n will store the length of array

    [ a, n ] = size( array );

    traverse through the array

    for i = 1 : n

     if element is found

        if array(i) == search_value

             value = search_value;

            index = i;

           break out of loop

            break;

                end

           end

end

array = [ 1 : 6 ];

search_value = 3;

[value,index] = SE3120_Activity6(array,search_value);

fprintf('Index = %d ', index);

Output: Index = 3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote