Question: Function in C. Having trouble outputing correct number What i have************************************************ double compute_sqrt(double x) { /* 2. This function computes the square root of a
Function in C. Having trouble outputing correct number

What i have************************************************
double compute_sqrt(double x) {
/* 2. This function computes the square root of a number. */
double next;
double last=1;
for(int i=1;i
next=0.5 *(last + x/last);
last=next;
}
return last;
}
int main() {
int test;
int x=1;
double n;
double k;
while(x==1) {
printf("Enter a positive integer: ");
scanf("%lf", &n);
k= compute_sqrt(n);
printf("Factorial of %lf", k);
}
printf(" Exiting program. ");
return 0;
}
When I enter 36, it should give me 6 but i doesnt. When i tranfered the code to java, it works, but doesnt in c.
2. Write a function that computes the square root of a number. The square root of a number x can be approximately computed as follows. First guess that the square root of x is 1. Then repeatedly get the next guess from the last guess using the rule next 0.5(last+ x/last) where last is the last guess and next is the next guess. Repeat ten times using a loop and the tenth guess will be approximately the square root. The function prototype is double compute sqrt (double x). The function computes the square root of x and returns the square root
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
