cs31day4 Wk2 W

cs31day4 Wk2 W - */ +operators use same conventions as...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
* / + - operators use same conventions as mathematics int n; // "int" limits the variable to be an integer cout << n; // undefined behavior because n was not defined ____________________ int n; cin >> n; int m = 23 // m=23 int p = 2 * m // p=46 double x = -2.76; double y = 12.345e-7; // y= 12.345 x 10^-7 double z = 23; // uses 23.0 int r = 3.89; // uses 3; it ignores the fraction portion if an operation contains at least one double and an integer, the answer will be a double. if an operation is between two integers, then the answer will be an integer 19.3/5.0 --> 3.86 19.3/5 --> 3.86 19/5.0 --> 3.8 significant figures 19/5 --> 3 cout << m / 2; // writes 11, not 11.5 % - modulus operater [gives the remainder] int t = m % 2; // sets t to 1 --> 23/2 = 11 remainder 1 find even/odd numbers using [# % 2]. if remainder is -, then even. If remainder is odd, then odd number. int a = 10; int b = a*a; int c = 25/(b-100); // problem! will divide by zero.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
// undefined behavior. programmer can tell program to do whatever they want. will probably crash by default int d = 1000; int e = d * d * d; int f = e * d;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

cs31day4 Wk2 W - */ +operators use same conventions as...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online