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

Could you write it with FOR LOOP only? Integer Grid Points R is already defined

ID: 3751246 • Letter: C

Question

Could you write it with FOR LOOP only?

Integer Grid Points R is already defined for you. For a circle of radius R, count how many (x,y) points exist within the circle (including on the circle itself) where x and y are both integer values. (Posed another way, how many integer grid points exist within the circle?) Store your answer in a variable named IGP. Note that R does not have to be an integer For example, for a circle of radius 2 (as shown in the image below), the IGP value is 13 (the points shown in pink) -3 -2 Hint, there is not a closed-ended formula for this problem. Your code must look at every (x.y) point and count the number of points that meet the criteria.

Explanation / Answer

function igp = getEnclosedPoints(r)
igp = 0;
for i = -ceil(r):ceil(r)
for j = -ceil(r):ceil(r)
if(i*i +j*j <= r*r)
igp = igp + 1;
end
end
end
end