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
- Microsoft Interview Question about Algorithm
- 243. You are in a maze, and you open your eyes so you ....
- Given number 1,2,3,4,5,6,7,8,9 find all sets that sums up to 10.....
- 153. There is a row of houses in which each house contains some amount of money ......
- 161. How to serialize and deserialize a n-ary tree?
- 265. Difference between AVL trees and Red black trees
- find the bug in the following code which concatenates...
- 260. What is bug in this code? correct it......
- 186. How do you test a function which would return the second smallest number in a BST?
- 246. An array is given like {1,4,5,2,3,6,7}
- More...
|