Make function called somthing(x) that loops through the vector x and for each number n in vector x it should display ‘n is divisible by 2’, ‘n is divisible by 3’, ‘n is divisible by 2 AND 3’ or ‘n is NOT divisible by 2 or 3’. Use a for loop, the function mod or rem to figure out if a number is divisible by 2 or 3, You can use any combination of if, else, and elseif. this is homework, i tried this code but
function[out]=divisible_m(x)x=input('Enter any Vector')if (rem(x,2)==0&&rem(x,3)==0) disp('divisible on 2 and 3')elseif (rem(x,2)==0&&rem(x,3)~=0) disp('divisible on 2')elseif (rem(x,2)~=0&&rem(x,3)==0) disp('divisible on 3')else disp('not divisible ')end end
this code let user to enter just 1 element and my question is how to let the user put matrix not single element and divisible each element in that matrix
Best Answer