Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mathematical Manipulation Data types Operator precedence Standard mathematical functions Worked examples.

Similar presentations


Presentation on theme: "Mathematical Manipulation Data types Operator precedence Standard mathematical functions Worked examples."— Presentation transcript:

1 Mathematical Manipulation Data types Operator precedence Standard mathematical functions Worked examples

2 Definition of data type Integer Floating: floating point number Floating, double F & Long double F IntegerFloating Double floating No of Bytes 248 No. of Bits* 163264 No. of significant digits 715 Range -32,768 to + 32,768 -3.4E+38 to +3.4E+38-1.7E+308 to +1.7E+308 Note An int beyond this range cannot be expressed in int but in float

3 Conversion of different variable type Auto-conversion occurring in calculation The integer variable will be automatically converted to a float variable and then manipulated with the given float variable { float i = 10.053; int j = 222; cout<<"i+j= "<< i+j << endl; // auto conversion of 222 into 222.000 before added to 10.053. }

4 Auto-conversion occurring in assignment When an integer variable is assigned to a float variable, the float variable will hold a float number of the same value. For example, { float i; int j; j=555 i=j; } { float x; int y; x=10.053 y=x; }

5 Operator precedence 1. operators * and / have higher precedence than + and -. 2. if two operators have equal precedence, then they obey a left-to-right rule. – For example, 3/4 * 2 means (3/4) *2.

6 Standard mathematical functions In C++, common math functions are provided in one of libraries – the math library. To use one of the functions, the include statement must be included at the head of the program: #include Expressions in C++Math meaningsExampleNote cos (x) in radian sin (x) in radian tan (x) in radian fabs(x)|x| fabs(-3)=3 log (x)lnx log10(x) log 10 x sqrt(x) x 1/2 pow(x,y) xyxy

7 Conversion of an angle in degree into one in radian x2 (angle in radian) = (3.14 / 180 ) * x1 (angle in degree). #include using namespace std; #include void main() { float x1, x2; cout<<”x1(in degree)=”; cin>>x1; x2=3.14/180*x1; cout<<”\n x2 (in radian)=”<<x2<<endl; }

8 Evaluation of the roots of a quadratic { float a, b,c,d, x1, x2; cin >> a>>b>>c; d=b*b - 4.0 * a * c; if (d < 0) { cout << "imaginary roots to be discriminated" << endl;} else { x1 = (- b + sqrt(d)) / (2.0 * a); x2 = (- b - sqrt(d)) / (2.0 * a); cout << "x1 = " << x1 << endl; cout << "x2 = " << x2 << endl; } }

9

10


Download ppt "Mathematical Manipulation Data types Operator precedence Standard mathematical functions Worked examples."

Similar presentations


Ads by Google