CS 17
int i = 1; int j = 2; int k = 3; double x = 1.0; double y = 2.0; double z = 3.0;
i + j == k; ((i + j) == k); ==> 1
k - i < y > x; (((k - i) < y ) > x); ==> 0
z - x + 1 != j + k - 2 * i; (((z - x) + 1) != ((j + k) - (2 * i))); ==> 0
Any non-zero value is interpreted as ``true.'' Zero is interpreted as ``false.''
#include <iostream.h>
int a, b, c;
void f1(void);
void f2(void);
int main()
{
int a;
a = 5;
b = 3;
c = 7;
cout << a << " " << b << " " << c << endl;
f1();
cout << a << " " << b << " " << c << endl;
return 0;
}
int d = 4;
void f1(void)
{
int c = 10;
a = 3;
b++;
cout << a << " " << b << " " << c << " " << d << endl;
f2();
cout << a << " " << b << " " << c << " " << d << endl;
}
void f2(void)
{
int d = 45;
a += 4;
b = 7;
c = d + a;
cout << a << " " << b << " " << c << " " << d << endl;
}
Each output value was worth 1.5 points. Here's the output:
5 3 7 3 4 10 4 7 7 52 45 7 7 10 4 5 7 52

The parameters n and r are integers. The function should return an
integer value. Your function should make use of a factorial function,
which you are also to write. Here is the definition of
:

and
are defined to have the value 1. Again, n is an integer.
The function should return an integer value.
// Prototypes.
int fact(int);
int choose(int, int);
int fact(int n)
{
int prod = 1;
while (n > 1)
{
prod *= n;
--n;
}
return prod;
}
int choose(int n, int r)
{
return fact(n) / (fact(n - r) * fact(r));
}
void printFloat(double number, int width, char fill, int precision)
{
cout << setw(width) << setfill(fill) << setprecision(precision)
<< setiosflags(ios::scientific) << setiosflags(ios::right)
<< value;
}