It should return false when the number does not have perfect square, otherwise it returns the root. But in this code it returns the root all the time. E.g. Input 5, root 2.
main()
{
int i;
int number=0;
int result=0;
for(i=0; i<10; i++){
printf("Testing:");
scanf("%i",&number);
result = isSquare(number);
if(result==0)
printf("Fail\n");
else
printf("%i\n",result);
}
}
int isSquare(int n)
{
float root = sqrt(n);
if (n == (int) n)
return root;
else
return 0;
}