WAP find square root of any number (without using sqrt() )?

Answers were Sorted based on User's Feedback



WAP find square root of any number (without using sqrt() )?..

Answer / 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

WAP find square root of any number (without using sqrt() )?..

Answer / akash dilwaria

#iclude<iostream.h>
#nclude<conio.h>
void main()
{
clrscr();
int n;
float sqrt;
cout<<"\n enter the number";
cin>>n;
sqrt=pow(n,0.5);
cout<<"\n square root of a number is="<<sqrt;
getch();
}

Is This Answer Correct ?    2 Yes 3 No

WAP find square root of any number (without using sqrt() )?..

Answer / avinash

private int sqrt()
{
int n = console.readline();

n = n*n;

return n;
}

Is This Answer Correct ?    5 Yes 11 No

Post New Answer

More OOPS Interview Questions

i had specified the access specifier for abstarct class member like (pure virtual function) as private.But it can be accessed by the derived class.How the private member of one class is accessed by other class.if any body face this problem and found the solution plz reply to me.

1 Answers   Syntel,


why in java first invoke public static void main(String args[]) method????Why not public static void method1(String args[])??

1 Answers  


#include <iostream> using namespace std; struct wow { int x; }; int main() { wow a; wow *b; a.x = 22; b = &a; a.x = 23; cout << b->x; return 0; }

1 Answers  


What is new keyword in oops?

0 Answers  


what is the use of mutable key word

3 Answers   HCL,






What is debug class?what is trace class? What differences are between them? With examples.

0 Answers  


What is encapsulation in ict?

0 Answers  


how to create thread in java?

17 Answers   IBM, Infosys, Wipro,


What is abstraction with example?

0 Answers  


What is destructor example?

0 Answers  


Which is faster post increment or pre increment ? and in which cases should u use either - to increase speed?

4 Answers   EA Electronic Arts,


Describe what an Interface is and how it?s different from a Class.

7 Answers   Spinsys,


Categories