WAP find square root of any number (without using sqrt() )?
Answer Posted / bhavya b
square of a no: n is the sum of first n odd no: for eg ..square of 7 is 1+3+5+7+9+11+13=49...
so we can find sqrt(m) by decrementing odd no:s from m upto m become 0 or less..then the no: of odd no:'s decremented will give the sqrt(m).
int sqroot(int m){
int n=0,i=1;
while(m>0){
m=m-i;
i+=2;
n++;
}
return(n);
}
| Is This Answer Correct ? | 6 Yes | 2 No |
Post New Answer View All Answers
Why is oop better than procedural?
What is inheritance in simple words?
What is object and example?
Can private class be inherited?
What does <> mean pseudocode?
what is different between oops and c++
What are the 4 main oop principles?
What is polymorphism in oop example?
Why is object oriented programming so hard?
Why do we need oop?
Describe these concepts: Polymorphism, Inheritance and Abstraction.
What is overloading and its types?
What are different oops concepts?
What is the difference between a constructor and a destructor?
What is encapsulation in oops?