Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Using exponents
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Ceevu




PostPosted: Mon May 22, 2006 1:31 am   Post subject: Using exponents

I use the MinGW 4.1 compiler and run in WinXP.

As for the Q:

I'm wondering what notation I would use to write exponents in C?

An example I'm working on is writing a program that calculates the volume of a sphere. Formula is: 4/3*pi*radius(cubed).


cheers and thanks in advance
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Mon May 22, 2006 1:59 am   Post subject: (No subject)

There is no exponent operator in C or C++, instead you can use the pow() function in math.h.
An example of usage:
c:
#include <stdio.h>
#include <math.h>

int main()
{
   printf("%d\n", (int)pow (5.0, 3.0)); //returns 5^3
   return 0;
}
Ceevu




PostPosted: Mon May 22, 2006 11:39 am   Post subject: (No subject)

Thanks a lot, Gandalf!
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: