Write a program that generates a vector with 30 random integers between –10 and 20 and then finds the maximum of all the elements that are divisible by 3.
if you can explain how you got to finding the maximum it well help. also please use matlab
Answer:
Given that:
Write a program that generates a vector with 30 random integers between –10 and 20 and then finds the maximum of all the elements that are divisible by 3.
v = randi([-10, 20], 1, 30)
max_div = -9;
for i=1:length(v)
if v(i) > max_div && rem(v(i), 3) == 0
max_div = v(i);
end
end
fprintf("Maximum of all elements that are divisible by 3 is %d\n",
max_div)
COVID 19 time so #stay home #stay safe
Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
Get Answers For Free
Most questions answered within 1 hours.