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

what is the use of template classes in c++

1 Answers  


How to Increment the value of the empid E001 for each and every employee by using the programe?

1 Answers   Accenture,


Can we create object of class with private constructor?

5 Answers  


What are the 5 oop principles?

0 Answers  


What is a class and object?

0 Answers  






What is multiple inheritance?

9 Answers   TCS,


What is this pointer in oop?

0 Answers  


can main method be overloaded...??? How..????

2 Answers   Satyam,


Explain the concepts involved in Object Oriented programming.

0 Answers   Wipro,


c++ provides classes...and classes do what we want but why then strcut are used...if we say data hiding... it is also provided by c++ in structs then why to prefer clasess

1 Answers   HCL, TCS,


what is the size of an empty class

12 Answers   Wipro,


What is function overloading?,describe it with the example.

5 Answers  


Categories