Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
Note: each expression should be taken as independent. I.e. if one expression modifies some variable values, those modifications do not carry over to the next expression.
// Function prototypes - each function what the name says it does
int abs(int j); // returns "absolute value" of j. defined in library cstdlib
double round(double x); // returns x rounded to nearest integer. defined in library cmath
string to_string(int val); // returns string representing val. defined in library string
// Variable definitions
int k = 4;
double x = -3.8;
string s = "The number of cookies I need: ";
| expression | type | value |
k + abs(x) | ||
x + abs(k) | ||
round(x) + k | ||
abs(x) = k | ||
k = round(x) | ||
s + to_string(k + 5) | ||
to_string(int(round(x))) | ||
(3 + 10)/round(x - 1) | ||
to_string(1) > to_string(2) | ||
to_string(1) + 3 |
~/$ ./hw 2/4, 6/9, 3/11, 21/5, 8/10; 3/11 is in lowest terms! 21/5 is in lowest terms!In writing this program, you need to define and use a function
gcd that takes
two positive integers and returns their greatest common divisor.
~/bin/submit -c=IC210 -p=hw16 hw.cpp