Points in Circle

You have the radius of a circle with the center in point (0,0). Write a function that calculates the number of points in the circle where (x,y) - the cartesian coordinates of the points - are integers. Example: for radius = 2 the result should be 13. 0 <= radius <= 1000 https://imgur.com/a/ydlsw3R
mail@pastecode.io avatar
unknown
csharp
3 years ago
292 B
2
Indexable
Never
int PointsInCircle(int radius) {
    int output = 0;
    for (int i = -radius; i <= radius; i++)
    {
        for (int j = -radius; j <= radius; j++)
        {
            if ((i*i + j*j) <= (radius * radius))
                output++;
        }
    }
    
    return output;
}