COS 126 Exercise Set 1 |
Answers |
These exercises are intended to guide class discussion and to help review some of the course material in preparation for the two midterms. Do not turn in solutions.
t = x; x
= y; y = t;
if (a > b) then c =
0;
if a > b { c = 0; }
if (a > b) c = 0;
c = 0
b = 0;
if (a > b) c = 0 else b = 0;
#include <stdio.h> int f(int x) { return x + 2; } int main(void) { int x; x = 4; printf("%d\n", f(x + 2)); return 0; }
lcc
compiler to
see what error messages it produces for semicolon errors.
int square (int x); { return x*x; } int main(void) { int a, b, c; c = 0 b = 0; if (a > b) c = 0 else b = 0; return 0; }
x
and y
.then
keyword in C.c = 0
.#include <stdio.h> int main(void) { int i, j; for (i = 1; i <= 9; i++) { for (j = 1; j <= 10; j++) printf("%3d", i*j); printf("\n"); } return 0; }