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

me get an assignent n its question is this 1.creat a set as in math i.ea={1,2} 2.insert element in it3. delete element don,t repeat any element 4.union 5. intersection of two sets plz help me i always pray for u n send me at ayeshawzd@hotmail.com f u have c++ how to program 5th addition then it is the 10.9 question in 10th chapter exercise

1 Answers  


what is the 3 types of system development life cycle

0 Answers  


Why multiple inheritance is not allowed?

0 Answers  


what is the virtual function overhead, and what is it used for ? i hope i can get and appropriate answers, thanks a lot....

6 Answers  


Round up a Decimal number in c++.. example Note = 3.5 is as 4 3.3 is as 3

3 Answers   Accenture, Cognizant, IBM,






what isthe difference between c structure and c++ class

5 Answers  


They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?

0 Answers  


wht is major diff b/w c and c++?

10 Answers  


what is data hiding.

3 Answers   Wipro,


What are generic functions and generic classes?

5 Answers  


write a programe to calculate the simple intrest and compund intrest using by function overlading

0 Answers  


What is nutshell in programming language?

1 Answers   Satyam, Tech Mahindra,


Categories