Visit Jeremy's Blog.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org [SOLVED] Using powers based on user input
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 11-28-2012, 02:14 AM #1 curious95 Member   Registered: Oct 2012 Location: /home/v Distribution: Slackware 14.0 Posts: 83 Rep: Using powers based on user input i noticed that C does not have an exponentiation operator. So i was wondering how does one add a power to variable which is based on user input? example: Code: ```int x; scanf("%d", &x); printf("%d",xe2 + xe5);``` where e is an exponentiation character, on a calculator e would be ^. (so x^2 + x^5)
 11-28-2012, 03:07 AM #2 JohnGraham Member   Registered: Oct 2009 Posts: 467 Rep: There's the function pow() (and associated powf() and powl()) in math.h.
 11-28-2012, 03:07 AM #3 acid_kewpie Moderator   Registered: Jun 2001 Location: UK Distribution: Gentoo, RHEL, Fedora, Centos Posts: 43,417 Rep: ok, so use "e" is pretty chuffing confusing given e referes to the exponentiation function / inverse natural log. ^ would mean power normally, not exponent, so 2^5 is 25, not 200000, which is 2 x 10^5. Use the math.h library, with the pow() function (which also contains exp() for the real e() function)
 11-28-2012, 06:41 AM #4 curious95 Member   Registered: Oct 2012 Location: /home/v Distribution: Slackware 14.0 Posts: 83 Original Poster Rep: understood, thanks for the answers

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post prravin1 Programming 1 05-04-2012 07:42 AM contra04 Programming 7 01-17-2012 04:38 PM helptonewbie Programming 8 07-07-2008 07:40 PM TSK2000 Linux - Software 1 12-30-2005 03:22 AM SCX Debian 6 09-04-2004 07:29 AM

LinuxQuestions.org

All times are GMT -5. The time now is 10:20 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -