summaryrefslogtreecommitdiff
path: root/graphs/piscine/int_sqrt/int_sqrt.c
blob: 4b2e5dba899b19c764cee22b57934233642c90de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int int_sqrt(int n)
{
    if (n < 0)
    {
        return -1;
    }

    if (n == 0 || n == 1)
    {
        return n;
    }

    int i;
    for (i = 1; i * i < n; i++)
    {
        continue;
    }

    return i - (i * i != n);
}