quick question passing data types for square root function (function parameters)
hey all i've already worked through the math of this problem and i'm ready to start the code but please i'm just getting 0.000 when I compile this program, I believe it's an issue with the conflicting float and int data types because there are a few. Please help just get the program to output correct squre root for 'c' which is about 31.622 (roughly with %.3f precision) and don't mind all the comments. Problem 9 - Project Euler
Code:
#include <stdio.h>
#include <math.h>
float square_root (int p);
float square_root (int p) // i got this code from Stackoverflow
{
float temp, sqt;
/*
printf("Enter number: ");
scanf("%d", &n);
*/
sqt = p/2;
temp = 0;
while (sqt != temp)
{
temp = sqt;
sqt = (p/temp+temp)/2;
}
return sqt;
}
int main ()
{
// rule
// if hypotonuse is known, divide sides a and b by square root of 2.
// sqare root 31.62 * 2
// a^2 + b^2 = 1000 = 31.623^2
printf("RULE: If hypotenuse is known, divide sides a and by by the square root of 2\n");
printf("insert hypotenuse special side value for 'c': \nc: ");
//scanf("%f", c);
int c = 1000;
int ret;
ret = square_root(c);
printf("%.3f\n", ret);
return 0;
}
/* side_a = 31.62/sqrt(2) side_b = 31.62/sqrt(2); */
/*(
while (c != 1)
{
// convert c (1000) to square root
//root = sqrt(c); // *c is done
//printf("%.3f", root);
//break;
printf("%.3f\n", ret);
break;
while (c % side_a == 0) // do division inside a while loop
{
// divide side_a by square root of 2
}
}
*/