Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Exercise on Variable Assignment and Arithmetic Operations - Prof. Carol L. Spradling, Assignments of Computer Science

An exercise for students to understand how variables are assigned new values based on arithmetic operations. The exercise includes six statements for each of two sets of variables, and students are required to determine the value of a variable named 'n' or 't' after each statement or group of statements is executed.

Typology: Assignments

2009/2010

Uploaded on 02/23/2010

apalmer14
apalmer14 🇺🇸

4 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
44-141 Exercise 4
1. Assume we have declared and initialized the variables below.
int n;
int j = 5;
int k = 3;
int m = 7;
What is stored in n after each statement?
(a) n = j + k;
n = 8
(b) n = j + k + m;
n = 15
(c) n = j / k + m;
n = 8
(d) n = j % k * m;
n = 14
(e) n = j % 2 + k * 4 - m / 3;
n = 11
(f) n = (j + k) * 2 - 10 / (m - k);
n = 14
2. Assume we have declared and initialized the following variables below.
double t;
double x = 3.5;
double y = 4.2;
double z = 12.35;
What is stored in t after each statement or group of statements is executed?
(a) t = x + y + z;
t = 20.05
(b) t = x – y * z;
t = -48.37
(c) t = x / x + z;
t = 13.35
pf2

Partial preview of the text

Download Exercise on Variable Assignment and Arithmetic Operations - Prof. Carol L. Spradling and more Assignments Computer Science in PDF only on Docsity!

44-141 Exercise 4

  1. Assume we have declared and initialized the variables below. int n; int j = 5; int k = 3; int m = 7; What is stored in n after each statement? (a) n = j + k; n = 8 (b) n = j + k + m; n = 15 (c) n = j / k + m; n = 8 (d) n = j % k * m; n = 14 (e) n = j % 2 + k * 4 - m / 3; n = 11 (f) n = (j + k) * 2 - 10 / (m - k); n = 14
  2. Assume we have declared and initialized the following variables below. double t; double x = 3.5; double y = 4.2; double z = 12.35; What is stored in t after each statement or group of statements is executed? (a) t = x + y + z; t = 20. (b) t = x – y * z; t = -48. (c) t = x / x + z; t = 13.

(d) t = x * (y + 2) * (z – 10); t = 50. (e) t = 1; t = t + 2; t = 3. (f) t = x + y + z; t = t * t + 2; t = 404.