Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 3 Variables & Expressions. Basic Operations Addition + Subtraction – Multiplication * Division / Modulus %

Similar presentations


Presentation on theme: "Lab 3 Variables & Expressions. Basic Operations Addition + Subtraction – Multiplication * Division / Modulus %"— Presentation transcript:

1 Lab 3 Variables & Expressions

2 Basic Operations Addition + Subtraction – Multiplication * Division / Modulus %

3 Compound Operations x += y;  x = x + y; x -= y;  x = x - y; x *= y;  x= x * y; x /= y;  x = x / y; x++;  x = x + 1; x--;  x = x - 1; x++ and ++x difference?

4 Float/Integer int a=5; float x; x=a/2; printf("x=%f",x); x=2 ? 5---2 x 2.52

5 Operator Precedence ( ) ++ -- * / % + -

6 #include Void main(void) { int a=10,b=3,c,d,e,f,g; float y,z; //basic operations c=a+b; d=a-b; e=a*b; f=a/b; g=a%b; Printf(“C=%d\tD=%d\nE=%d\tF=%d\nG=%d\n\n”,c,d,e,f,g); } Example 1

7 #include Void main(void) { int a=10,b=3,c,d,e,f,g; float y,z; //compound operations c+=a; d-=b; e*=a; f/=b; g++; Printf(“C=%d\tD=%d\nE=%d\tF=%\ d\nG=%d\n\n”,c,d,e,f,g); } Example 2

8 #include Void main(void) { int a=10,b=3,c,d,e,f,g; float y,z; //integer/ float: is the result correct ? y=b/2; Printf(“Y=%f\n”,y); //what is the order of the operations ? Z=4+5*3; Printf(“z=%f\n\n”,z); } Example 3

9 Mathematical Functions Use math.h (#include ) Sample functions pow(a,b)a power b (a b ) sin(a)sine of a cos(a)cosine of a sqrt(a)square root of a log(a)Natural logarithm of a log10(a)base-10 logarithm of a


Download ppt "Lab 3 Variables & Expressions. Basic Operations Addition + Subtraction – Multiplication * Division / Modulus %"

Similar presentations


Ads by Google