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


Please Help Members By Posting Answers For Below Questions

What are the 3 principles of oop?

714


explain sub-type and sub class? atleast u have differ it into 4 points?

1933


Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?

4343


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(); }

2078


What is overloading in oop?

653






Get me a number puzzle game-program

1783


What are the two different types of polymorphism?

771


What are properties in oop?

695


Why do we use inheritance?

716


What is object in oops?

718


What is a superclass in oop?

788


to find out the minimum of two integer number of two different classes using friend function

1740


How long to learn object oriented programming?

667


hi all..i want to know oops concepts clearly can any1 explain??

1757


What are objects in oop?

701