We are going to use another library <cmath>
Then we can use all math related library provided by C++
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
double num1; //real number in c++
cout<<"Pick your number.."<<endl;
cin>>num1; //get value from user
double num2; //doesn't have a value yet;
num2 = sqrt(num1); //a basic math function square root, num1 is an argument
//some functions have arguments more than one.
cout<<"The square root of variable "<<num1<< " is "<<num2<<endl;
//let's use another function pow()
num1 = pow(2.0, 4.0); //16 = 2^4
//random number
num1 = rand(); //you don't need any argument; automatically assigned
cout<<num1<<endl;
system("pause");
}
'Computer General > C++ development from the beginning' 카테고리의 다른 글
Address Operator & Pointer (0) | 2014.12.12 |
---|---|
Beginning Loop (0) | 2014.12.12 |
Beginning Arrays (0) | 2014.12.12 |
User Defined Functions (0) | 2014.12.12 |
How to start C++ for beginners (0) | 2014.12.10 |