473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

C function help

Hi Im really new to programming and need help with this problem:
Write a C function named root4( ) that returns the fourth root of the argument passed to it.
Thanks.
Oct 16 '06 #1
3 2355
There is a function called sqrt which is in math.h

The forth root is sqrt(sqrt(value));

unless of course you are meant to write your own square root algorithm.
Oct 16 '06 #2
Actually it says i need to create a function named root4 which is to take a single double parameter and return the fourth root of the parameter as a double value. I also need to place this function in a loop that will allow the user to input a double value, call root4 with that value, then display the fourth root on the screen and the loop is supposed to continue till a negative number is entered.

If you could show me how to do all this i would greatly appretiate it , thanks
Oct 16 '06 #3
Banfa
9,065 Expert Mod 8TB
Use a binary chop method.

NOTE: you can't find the 4th root of a negative number without going into complex arithmatic so for now reject all negative numbers.

In this method you start with a lower limit that is definately too small (0 is good) and a upper limit that is definately too large (the number itself). Then you find a value half way between the 2 numbers and see if this is large or smaller than the root (by multiplying it by itself 4 times and seeing if the result is larger or smaller than the required number). If it is larger you replace the upper limit with the new value and if it is smaller you replace the lower limit. You keep going until the upper and lower limit are the same to a set tolerance.

It is called a binary chop because at each step you discard half the values in the current range so it finds the result fairly quickly.

In steps it is

Let Number be the value we want the root for
Let Tolerance be the tolerance required in percentage
  • Set LowerRoot to 0
  • Set UpperRoot to Number
  • Set Guess = (LowerRoot+UpperRoot)/2
  • Set Calc = Guess * Guess * Guess * Guess
  • If Calc > Number Then UpperRoot = Guess Else LowerRoot = Guess
  • if fabs(UpperRoot - LowerRoot/UpperRoot)*100 < Tolerance Then End Calculation
  • Goto 3
Oct 16 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Edward King | last post by:
Hi! I am trying to achieve the following: I have a number of help pages (in the format help_nn.php where nn=helpid). I want to be able to open a particular help page by calling the function...
4
by: Joneseyboy | last post by:
Hi, I'm new to this so I could really do with some help! I am using VB.net to create a small game. basically there is a Textbox, a button and a listbox. The user enters a number into the...
2
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
1
by: intl04 | last post by:
I'm trying to set up a query that will include a new field ('Days until completion') whose value is derived from the DateDiff function. I think I have the syntax correct but am not sure. Days...
7
by: Mike D. | last post by:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving...
4
by: George Durzi | last post by:
I created a simple user control which contains a hyperlink to link the user to a topic in a compiled help file. I named all my help topics to have the same name as the aspx they are for. So in...
7
by: Jimakos Bilakis | last post by:
Hi guys! I'm using the C++ Builder 6 Enterprise Edition where I create some tables in Paradox and with the help of a structure i pass my data from the form (Edit boxes) to the Paradox table with...
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
1
by: Beamor | last post by:
function art_menu_xml_parcer($content, $showSubMenus) { $doc = new DOMDocument(); $doc->loadXML($content);//this is the line in question $parent = $doc->documentElement; $elements =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.