Write a function a avmathscorem e This function should take

Write a function a = av_math_score(m, e). This function should take as input two arrays m and e (consisting of Math and English scores of a bunch of students). If m and e have different length, it should prompt an error message \"Wrong input\". If there is no student with English score 50 or above, it should prompt error message \"None of the students qualify\". Otherwise, it should give output the average Math score of all those students who has scored 50 or above in English.

Solution


function a=av_math_score(m,e)

length1=length(m);    %length function returns length of the array

length2=length(e);

avg=0;

   y=0;

if length1!=length2    %compare both arrays length and do the below statement if they are not same

    fprintf(\'Wrong Input\' );   

else    %if they have same length do this

     for x=0:length2 %loop to iterate through second array to check whether atleast one element is more than 50

       if e(x)>50

         x=x-1;

         break

        end

      end

     if x==length2 //if no element>50 then do the following

       fprintf(\'None of the Students qualify\');

     else //if there atleast one elemt more than 50

      for n=0:length1

        if e(n)>50 //for the element in e whose value is greater than 50

          y=y+1; //increment count of elements whose value is more than 50

          avg=avg+m(n); //add the corresponding element of m to avg

         end

       end

      avg=avg/y    //average is determined by dividing avg by total no of elements in e whose value is more than 50

     end

end

end

 Write a function a = av_math_score(m, e). This function should take as input two arrays m and e (consisting of Math and English scores of a bunch of students).

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site