Computer Science, asked by sonam1010, 1 year ago

WAP to input a no. and check whether it is a perfect square or not

Answers

Answered by Anonymous
1

Hi,

I assumed that question is related to javascript.

function isSquare (number) {

var leftOver = Math.sqrt(number) % 1;

if (leftOver === 0) {

var squareRoot = Math.sqrt(number);

document.write('Yes, ' + number + ' is a perfect square number <br>Square root of ' + number + ' is ' + squareRoot);

} else {

document.write('No, ' + number + ' is NOT a perfect square number');

}

}

isSquare(9);

above code will ouput:

Yes, 9 is a perfect square number

Square root of 9 is 3

Hope it helps.


Similar questions