3 Replies - 1856 Views - Last Post: 08 February 2013 - 07:47 PM Rate Topic: -----

#1 calipolo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.

THANKS IN ADVANCE!

Is This A Good Question/Topic? 0
  • +

Replies To: Writing my own square root function

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3590
  • View blog
  • Posts: 11,168
  • 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?
Was This Post Helpful? 0
  • +
  • -

#3 calipolo  Icon User is offline

  • New D.I.C Head

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

Re: Writing my own square root function

Posted 08 February 2013 - 04:38 PM

View PostSkydiver, 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.
Was This Post Helpful? 0
  • +
  • -

#4 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • 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.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1