The code is OK..Its just that it is taking too long to run.The following code prints out the steps.
while(div<i)
{
printf("%lld\n",div);
if(i%div == 0)
{
largest=div;
}
div+=1;
}
As per algorithm point i would recommend you to initialize div = 600851475143/2
and count backwards