[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Square root

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 24
Thread images: 2

Hi guys, im new at C, idk whats wrong with my program, can anyone help me out? or maybe I should go ask /b
?
>>
>>9127527
>>>/g/etthefuckout
>>
File: 1358714884213.gif (350KB, 500x344px) Image search: [Google]
1358714884213.gif
350KB, 500x344px
>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?
>>
>>9127537
>>9127542
>>9127717
How about we see your C implementation of square root?
>>
>>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
these guys too:
>>9128317
>>9128479
>>9128565
>>
>>9128720
Yeah it's auto generated. Still looks retarded.
>>
>>9127527
>printf("raiz(%d)=%d",n,n);
>n
and another
>n
>>
>>9127527
>Xcode

real men use vim and the command line

>>9128918
well spotted

There are also some short vs. int gotchas. Make everything int for simplicity.
>>
>>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()
>>
>>9128722
cool story bro

>>9128954
http://lmgtfy.com/?q=c+sqrt
Thread posts: 24
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.