Writing my own square root function

Page 1 of 1

3 Replies - 2893 Views - Last Post: 08 February 2013 - 07:47 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=311639&amp;s=628f4cb6dcafd4a444185948498ae7fa&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 calipolo

Reputation: 0
• Posts: 2
• Joined: 08-February 13

Writing my own square root function

Posted 08 February 2013 - 03:32 PM

I have to write my own square root function using:
x=n-1
return 1+(1/2)x-(1/8)x^2+(1/16)x^3-(5/128)x^4

it will be named "doublemy_sqrt_1(double n)"

then write a main that prints n, sqrt(n) and my file for n=3.14159*10^kth for k=-100, -10, -1, 0, 1, 10, and 100.
I am supposed to use the code
```for(auto k: {-100, -10, -1, 0, 1, 10, 100}){
n=3.14159*pow(10.0, k);
//cout goes here
}
```

then I need to modify it so I can print the relative error as a percent, by adding a column
```relative_error_per_cent=100*((my_sqrt_1(n)-sqrt(n))/sqrt(n)
```
. Line up the columns using
```setw()
```
, ect.

Is This A Good Question/Topic? 0

Replies To: Writing my own square root function

#2 Skydiver

• Code herder

Reputation: 4378
• Posts: 14,134
• Joined: 05-May 12

Re: Writing my own square root function

Posted 08 February 2013 - 04:18 PM

So what problem are you encountering? What have you tried?

#3 calipolo

Reputation: 0
• Posts: 2
• Joined: 08-February 13

Re: Writing my own square root function

Posted 08 February 2013 - 04:38 PM

Skydiver, on 08 February 2013 - 04:18 PM, said:

So what problem are you encountering? What have you tried?

I am very new to c++ (like within the last two weeks). I don't know how to even start programming this. I know the files I need to include, but that's about it.

• D.I.C Lover

Reputation: 331
• Posts: 1,168
• Joined: 01-April 11

Re: Writing my own square root function

Posted 08 February 2013 - 07:47 PM

There's no practical way to start people off on their programs. That is VERY much left up to you. You are the person hearing the instructor and/or reading the textbook.

If and when you get stuck, THEN post your code so we know just what you're doing (use code tags), and ask your questions/describe your problem. Be sure to include any compiler errors or warnings. We will then try to help.

But the start of a program is entirely up to you. This is a common protocol for all the programming forums I have seen. The program you're describing requires some familiarity with the language, imo.