Problem Description
Given a number A. Return square root of the number if it is perfect square otherwise return -1.
Note: A number is a perfect square if its square root is an integer.
Problem Constraints
1 <= A <= 108
Input Format
First and the only argument is an integer A.
Output Format
Return an integer which is the square root of A if A is perfect square otherwise return -1.
/**
* @input A : Integer
*
* @Output Integer
*/
#include<math.h>
int solve(int A) {
int i;
int sqrtNo = sqrt(A);
if(sqrtNo*sqrtNo == A)
{
return sqrtNo;
}
else
{
return -1;
}
}