C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old March 3rd, 2003, 01:53 PM
cemlouis cemlouis is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 205 cemlouis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 46 m 40 sec
Reputation Power: 0
Question Not right pow result???

Hi, a little question about a friend's school homework the question is in the attachment... I made a code but not giving the right result i mean when we solve the equation with a hand calculator the result is different... so the code of mine is:

Code:
  
    /* Numbers needed for the manupulation */
    double A = 5, B = 24, X, power=0.2; /* could be 1/5 either */
    /* ----------------------------------- */
    
    X = pow (A,power) * tan (B);
    
    /* Outputs the result on the screen */
    printf("The number X : %f\n",X);


This one gives an output of: -2.945580

Another approach for this:

Code:
    /* Numbers needed for the manupulation */
    double A = 5, B = 24, X; /* could be 1/5 either */
    /* ----------------------------------- */
    
    X = pow (A,1/5) * tan (B);
    
    /* Outputs the result on the screen */
    printf("The number X : %f\n",X);


This one give an output of: -2.134897

So two of them wrong the right result is: 0.614295223

So my question: How can i reach this result by ansi c ??? Thanx for reading...

Reply With Quote
  #2  
Old March 3rd, 2003, 02:02 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
your problem with #1 is that the tan() function expects rad numbers, not degrees. try "24.0*pi/180.0" instead.

for #2 it is this: (this is also why i used the ".0" above)
pow(...,1/5) - the "1/5" is an integer division. both sides are integers and such will be the result (0). try "1.0/5.0" instead.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Last edited by M.Hirsch : March 3rd, 2003 at 02:04 PM.

Reply With Quote
  #3  
Old March 3rd, 2003, 03:09 PM
cemlouis cemlouis is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 205 cemlouis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 46 m 40 sec
Reputation Power: 0
thanx it works now...

Code:
    /* Numbers needed for the manupulation */
    double A = 5.0, B, PI = 3.14, X, power = 1.0/5.0; 
    /* ----------------------------------- */
    B = 24.0*PI/180.0;
    X = pow (A,power) * tan (B);
    
    /* Outputs the result on the screen */
    printf("The number X : %f\n",X);


........................................................

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Not right pow result???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway