Interview Questions

200. Write code for finding square root of a given no.

Microsoft Interview Questions and Answers


(Continued from previous question...)

200. Write code for finding square root of a given no.

Question:
Write code for finding square root of a given no.


maybe an answer:


#include
void main(){
long int n,i,sum=0,k=1,f=0;

printf("ENTER THE NUMBER");
scanf("%ld",&n);
while(1){
sum+=(2*k-1);
if(sum==n)
{
f=1;
break;
}
else if(sum>n)
break;
k++;
}

if(f==1)
printf("This Number is Square Number Square root is:%d",k);
else
printf("This Number is not a Square Number");

}

(Continued on next question...)

Other Interview Questions