C
Programming and Technical
Programming
Program
logic of c program to find square root of a number without using sqrt(x) function
Read Solution (Total 4)
-
- #include
#include
float sqroot( float x){
float a , b;
a = x; // copy given value to 'a'
do{
b = a;
a = (a + x/a)/ 2; //This equation is from Newton-Repson Method
}
while( a!= b); // execute loop until a == b
return(a); // 'a ' or 'b' is sqroot of 'x'
}
main(){
float x;
printf("Enter any number n");
scanf("%f", &x);
if( x > 0)
printf(" SQRT(%f) = %fn", sqroot( x));
else
if(x < 0)
printf(" SQRT(%f) = %fi n", sqroot( -x));
else
printf(" square root is 0 n");
getch();
}
- 10 years agoHelpfull: Yes(6) No(0)
- float sqroot( float x){
float a , b;
a = x; // copy given value to 'a'
do{
b = a;
a = (a + x/a)/ 2; //This equation is from Newton-Repson Method
}
while( a!= b); // execute loop until a == b
return(a); // 'a ' or 'b' is sqroot of 'x'
}
- 10 years agoHelpfull: Yes(1) No(0)
- float sqroot( float x){
float a , b;
a = x; // copy given value to 'a'
do{
b = a;
a = (a + x/a)/ 2; //This equation is from Newton-Repson Method
}
while( a!= b); // execute loop until a == b
return(a); // 'a ' or 'b' is sqroot of 'x'
}
- 10 years agoHelpfull: Yes(0) No(0)
void main()
{
float i,num;
printf( "Enter number : ");
scanf("%f",&num);
for(i=2.0;i- 10 years agoHelpfull: Yes(0) No(0)
C Other Question