ft_sqrt
#include <unistd.h>
int ft_sqrt(int nb)
{
int i;
i = 0;
while (i <= nb)
{
if (i * i == nb)
return (i);
i++;
}
return (0);
}
타임 아웃이 발생했다. 따라서 코드를 다음과 같이 수정해야 한다.
#include <unistd.h>
int ft_sqrt(int nb)
{
long long num;
long long i;
i = 0;
num = nb;
while (i * i <= num)
{
if (i * i == num)
return (i);
i++;
}
return (0);
}
/*
#include <stdio.h>
int main(void)
{
printf("%d", ft_sqrt(2147483647));
}
*/
long long 자료형인 num에 nb값을 넣고 while문 안의 i를 i*i로 수정했다.