please i need help with this right now 1-Create a comparison table for while, if
ID: 3806799 • Letter: P
Question
please i need help with this right now
1-Create a comparison table for while, if-else and for loops. Explain each loop and provide an example of it.
2-
Review following program and fill out the missing values on the code segments. [5]
if val < 38
ans=4 * val + 2
else if val < 13
ans = val – 2
else
ans = 4
end
end
when val = 38
ans = _______
when val = 14
ans = _______
when val =
ans = ______
if cal < 22
reading = 2 * cal
else if cal < 12
reading = 12 – cal
else if cal < 66
reading = sqrt(cal)
else
reading = cal
end
end
end
when cal = 10
reading = ____
when cal = 11
reading = _____
when cal = 66
reading = ____
when cal =64
reading = _____
3- Write a Matlab function to find prime numbers from 1 to 100. (don’t use isprime command)
if val < 38
ans=4 * val + 2
else if val < 13
ans = val – 2
else
ans = 4
end
end
when val = 38
ans = _______
when val = 14
ans = _______
when val =
ans = ______
if cal < 22
reading = 2 * cal
else if cal < 12
reading = 12 – cal
else if cal < 66
reading = sqrt(cal)
else
reading = cal
end
end
end
when cal = 10
reading = ____
when cal = 11
reading = _____
when cal = 66
reading = ____
when cal =64
reading = _____
Explanation / Answer
Hi, I have answered Q2 completely.
Please repost others in separate post.
a)
if val < 38
ans=4 * val + 2
else if val < 13
ans = val – 2
else
ans = 4
end
end
when val = 38
ans = 4
when val = 14
ans = 4*14 + 2 = 58
b)
if cal < 22
reading = 2 * cal
else if cal < 12
reading = 12 – cal
else if cal < 66
reading = sqrt(cal)
else
reading = cal
end
end
end
when cal = 10
reading = 2*10 = 20
when cal = 11
reading = 2*11 = 22
when cal = 66
reading = cal = 66
when cal =64
reading = sqrt(64) = 8
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.