Download presentation
Presentation is loading. Please wait.
Published byAustin Jones Modified over 9 years ago
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.