473,734 Members | 2,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble calculating 5th root of a given number using C

Hi Friends

Please help me to write a C program to find the 5th (fifth) root of a given number.
Ex:(1) Input : 32
Output : 5th root of 32 is 2

Ex:(1) Input : 243
Output : 5th root of 243 is 3

Click here : www.c4swimmers.esmartguy.com to Test Your C Programming Strengths.
Waiting for your reply.

Regards
Kishor
Nov 14 '05 #1
13 12744

"Kishor" <na***********@ rediffmail.com> wrote in message
news:84******** *************** **@posting.goog le.com...
Hi Friends

Please help me to write a C program to find the 5th (fifth) root of a given number. Ex:(1) Input : 32
Output : 5th root of 32 is 2

Ex:(1) Input : 243
Output : 5th root of 243 is 3

Click here : www.c4swimmers.esmartguy.com to Test Your C Programming Strengths.

Waiting for your reply.

Regards
Kishor


Is one allowed to use the standard math.h ?
If so, then
double result = pow(32, 1/5);
should give you 2.0
Allan
Nov 14 '05 #2
nrk
Allan Bruce wrote:

"Kishor" <na***********@ rediffmail.com> wrote in message
news:84******** *************** **@posting.goog le.com...
Hi Friends

Please help me to write a C program to find the 5th (fifth) root of a given number.
Ex:(1) Input : 32
Output : 5th root of 32 is 2

Ex:(1) Input : 243
Output : 5th root of 243 is 3

Click here : www.c4swimmers.esmartguy.com to Test Your C Programming

Strengths.

I ran some of the code there through the DS9K, and now there are nasal
demons all over the place :-)

Waiting for your reply.

Regards
Kishor


Is one allowed to use the standard math.h ?
If so, then
double result = pow(32, 1/5);
should give you 2.0


Fortunately, it gives me 1.0 as expected :-) Perhaps you meant this?:

double result = pow(32, 1/5.);

-nrk.
Allan


--
Remove devnull for email
Nov 14 '05 #3
"Allan Bruce" <al*****@TAKEAW AYf2s.com> wrote in message
news:bv******** **@news.freedom 2surf.net...
"Kishor" <na***********@ rediffmail.com> wrote in message
news:84******** *************** **@posting.goog le.com...
Hi Friends

Please help me to write a C program to find the 5th (fifth) root of a

given number.
Ex:(1) Input : 32
Output : 5th root of 32 is 2

Ex:(1) Input : 243
Output : 5th root of 243 is 3

Click here : www.c4swimmers.esmartguy.com to Test Your C Programming

Strengths.


Waiting for your reply.

Regards
Kishor


Is one allowed to use the standard math.h ?
If so, then
double result = pow(32, 1/5);
should give you 2.0


Or 1.0 at the very least. Try 1.0/5.0.

This approach is good enough for a homework assignment,
but not industrial strength.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Nov 14 '05 #4
P.J. Plauger writes:
Or 1.0 at the very least. Try 1.0/5.0.

This approach is good enough for a homework assignment,
but not industrial strength.


I take it for granted that you are right. But what would you recommend for
someone who does not wish to make this a life's work?
Nov 14 '05 #5
Kishor wrote:
Hi Friends

Please help me to write a C program to find the 5th (fifth) root of a given number.
Ex:(1) Input : 32
Output : 5th root of 32 is 2

Ex:(1) Input : 243
Output : 5th root of 243 is 3


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <float.h>

inline double root(double x)
{
return pow(x, 0.2);
}
inline double original(double x)
{
return pow(x, 5.);
}

int main(void)
{
size_t pass;
const size_t maxpass = 10;
double x;
const double upperlimit = 1000.;
srand((unsigned ) time(0));
for (pass = 0; pass < maxpass; pass++) {
x = upperlimit * rand() / (1. + RAND_MAX);
printf("number: %.*g\n", DBL_DIG, x);
printf("5th root: %.*g\n", DBL_DIG, x = root(x));
printf("root to 5th power: %.*g\n\n", DBL_DIG, original(x));
}
return 0;
}

number: 349.12674268707 6
5th root: 3.2254968589367 2
root to 5th power: 349.12674268707 6

number: 933.51386301219 5
5th root: 3.9266677391732 4
root to 5th power: 933.51386301219 5

number: 337.09432277828 5
5th root: 3.2029509480995 5
root to 5th power: 337.09432277828 5

number: 921.04862164706
5th root: 3.9161246903652 7
root to 5th power: 921.04862164706

number: 193.95603332668 5
5th root: 2.8677458418489 5
root to 5th power: 193.95603332668 5

number: 536.52641875669 4
5th root: 3.5149424791371 3
root to 5th power: 536.52641875669 4

number: 769.72117181867 4
5th root: 3.7780411723776 9
root to 5th power: 769.72117181867 4

number: 245.49040617421 3
5th root: 3.0061240969129 7
root to 5th power: 245.49040617421 3

number: 818.88967892155 1
5th root: 3.8251201345917 3
root to 5th power: 818.88967892155 1

number: 422.26747702807 2
5th root: 3.3505609816076 8
root to 5th power: 422.26747702807 2

--
Martin Ambuhl
Nov 14 '05 #6
Allan Bruce wrote:

Is one allowed to use the standard math.h ?
If so, then
double result = pow(32, 1/5);
should give you 2.0


Bullshit. It yields 1.0

--
Martin Ambuhl
Nov 14 '05 #7
On Mon, 02 Feb 2004 18:45:09 GMT, Martin Ambuhl <ma*****@earthl ink.net> wrote:
Allan Bruce wrote:

Is one allowed to use the standard math.h ?
If so, then
double result = pow(32, 1/5);
should give you 2.0


Bullshit. It yields 1.0


Forgive me if I misunderstand, but could someone explain to me what value 32^0
is? If I read the statement
double result = pow(32, 1/5);

correctly, that's what the statement is computing.

--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers')
Nov 14 '05 #8
Lew Pitcher <Le*********@td .com> spoke thus:
Forgive me if I misunderstand, but could someone explain to me what value 32^0
is? If I read the statement
double result = pow(32, 1/5);

correctly, that's what the statement is computing.


You're reading it correctly. 32 (or any number other than 0) raised
to the zero power gives 1.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #9

"Martin Ambuhl" <ma*****@earthl ink.net> wrote in message
news:VU******** *********@newsr ead3.news.atl.e arthlink.net...
Allan Bruce wrote:

Is one allowed to use the standard math.h ?
If so, then
double result = pow(32, 1/5);
should give you 2.0


Bullshit. It yields 1.0


sorry it should have read
double result = pow(32.0, 1/5.0);

Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4964
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
8
4351
by: Ricky Romaya | last post by:
Hi, I'm working on a file upload script. I need to calculate the CRC32 of the file(s) which are successfully uploaded. How can I do this? PHP only have CRC32 function for strings. However, the uploaded file(s) are mostly binaries, and assumed have large size (5-12 MB per file). Are there any ways other than CRC32 (which supported by default PHP installation) to generate a unique hash of an arbitrary files? (the users of my script are...
8
1414
by: ali | last post by:
Hi, I'm trying to work on a recursive function that will give me root valuefor a given number. What i mean by root value is, if given 13, the answer is 1+3 = 4. If given 65, the answer is 2, i.e, 6+5=11, and 1+1=2. The final answer is always less than 10. I've been able to work on the code, but i can get it to work for
4
15610
by: 21novembre | last post by:
Hi all, I got a quite strange problem when I tried to setup a database backup shell. I put it this way: "bin/mysqldump --opt --user=xxx --password=xxx DB > DB.bak" However, error 1045 came to me to say "Access denied for user 'xxx'@'localhost' (using password: YES) when trying to connect". None the less, I'm absolutely full of confidence on my correct username and password, simply because if I do it this way: "bin/mysqldump --opt...
14
20985
by: Protoman | last post by:
How do I write a function to calculate the nth root of a number; I'm sick of using pow() with a fractional exponent to do the job. Got any ideas on how to do this? Thanks for the help!!!
4
8489
by: sathyashrayan | last post by:
(This is not a home work question) Dear group, I want a program to find one number between a set of natural number.A program to guess a number in between a Natural number set.This should be a simple task but my mind suddenly got stuck. I am trying to implement a square root function as a practice. I am able to code for the perfect square
3
7167
by: weston | last post by:
I'm making a foray into trying to create custom vertical scrollbars and sliders, and thought I had a basic idea how to do it, but seem to be having some trouble with the implementation. My thinking was: (a) create a div for the slider / scroll nub to move within (b) attach event handlers which, onmousedown, specify the slider/nub is moveable, and onmouseup, specify it's not (c) attach an event handler to the contaning div which,...
6
2263
by: Gonzalo Monzón | last post by:
Hi all! I have been translating some Python custom C extension code into Python, as I need these modules to be portable and run on a PocketPC without the need of compile (for the purpose its a must 2.4 as it is the last PythonCE release with great improvements). But I've been stuck with a script wich does not work as expected once translated to python, 2.4
5
13376
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.