Hi guys, im new at C, idk whats wrong with my program, can anyone help me out? or maybe I should go ask /b
?
>a square root method
>Copyright Armando
>mexican coding
[math] \displaystyle
\sqrt {x^2} \ne \pm x, \quad \sqrt {x^2} = \left | x \right |
\\
|x| =
\begin{cases}
\;\;\; x & ,x \geq 0 \\
-x & ,x < 0
\end{cases}
[/math]
>>9127737
This is correct.
>>9127527
use a recursive binary search so that ita n log n
Your code can be simplified:
Input n
Print n and n
>Copyright © 2017 Armando.
>Copyright © 2017 Armandillo.
>>9127527
>Armando
lol how much money do you want for me to license your code?
>>9127527
I know next to nothing about C but I can tell you're over-engineering.
Here you go.
[code]
#include <stdio.h>
int main(void)
{
int n = 144;
int i;
for (i = 1; i <= n/2; ++i)
if (i*i == n) printf("sqrt(%d) = %d\n", n, i);
}
[/code]
>>9128573
sqrt()
Read C spec, fix the width of your variables or the shift. Anyway, use sqrt from math.h because you won't outperform it on most architectures and it's portable.
>>9127527
Stop being retarded and use Scheme instead. It works and is much more beautiful.
(define (squareroot x)
(define (iteration currentvalue iterationsleft)
(if (= iterationsleft 0)
currentvalue
(iteration (/ (+ currentvalue (/ x currentvalue)) 2) (- iterationsleft 1))))
(iteration 1 10))
>>9128593
This. Or use the power function to 0.5.
>>9127542
>has never coded in his life
>>9128720
Yeah it's auto generated. Still looks retarded.
>>9127527
>printf("raiz(%d)=%d",n,n);
>n
and another
>n
>>9128592
I dont know C, but ive been learning python. Do you need to import a math library to use? In python you have to import math to use sqrt()