Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



C++ FAQs (2nd Edition)    (ISBN: 0201309831)


 

 List Price: $44.99
 Our Price: $44.99
 Used Price: $12.00

 Release Date: 11 December, 1998
 Manufacturer: Addison-Wesley Pub Co (Paperback)
 Sales Rank: 61,452

 Author: Marshall P. Cline, Greg A. Lomow, Mike Girou









More Info

 Math.h Examples 2002-01-17 23:04:22
  cpp 
Category: source:cpp:math
Description: Examples of the functions in math.h
Platform: win
Author: detour
Viewed: 6921
Rating: 3.4/5 (39 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
math.cpp
/* math.cpp by detour detour@metalshell.com
 *
 * Examples of the functions in math.h
 *
 * http://www.metalshell.com/
 *
 */

#include <iostream.h>
#include <math.h>

#define PI 3.14159265

int main() {
  int num[3] = { 81, 1000, -503};
  double dnum = 5.356;

  cout << "The square root of 81 is " << sqrt(num[0]) << endl;
  cout << "The absolute value of -503 is " << abs(num[2]) << endl;
  cout << "Log base 10 of 100 is " << log10(num[1]) << endl;
  cout << "The ceiling of 5.356 is " << ceil(dnum) << endl;
  cout << "The floor of 5.356 is " << floor(dnum) << endl;
  cout << "The sine of PI / 2 is " << sin(PI / 2) << endl;
  cout << "The cosine of PI is " << cos(PI) << endl;
  cout << "The arcsine of .5 is " << asin(.5) * 180 / PI << " degrees\n";
  cout << "The arccosine of .5 is " << acos(.5) * 180 / PI << " degrees\n";
  cout << "The arctangent of .5 is " << atan(.5) * 180 / PI << " degrees\n";
  cout << "2 to the power of 5 is " << pow(2,5);

  return 0;
}
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?