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
What are the 3 principles of oop?
explain sub-type and sub class? atleast u have differ it into 4 points?
Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?
What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }
What is overloading in oop?
Get me a number puzzle game-program
What are the two different types of polymorphism?
What are properties in oop?
Why do we use inheritance?
What is object in oops?
What is a superclass in oop?
to find out the minimum of two integer number of two different classes using friend function
How long to learn object oriented programming?
hi all..i want to know oops concepts clearly can any1 explain??
What are objects in oop?