Académique Documents
Professionnel Documents
Culture Documents
Programming
Languages - C
Lecture 1
Matthew P. Johnson
Columbia University
Fall 2003
character
Result is similar to Java’s
System.out.println()
0 <0-in-Celsius>
20 <20-in-Celsius>
… …
300 <300-in-Celsius>
Math?
C = 5/9 * (F-32)
fahr = lwr;
while (fahr <= upr) {
cels = 5*(fahr-32)/9;
printf(“%d\t%d\n”, fahr, cels);
fahr = fahr + step;
}
10/17/08 } CS3101-1, Lecture 1 28
C Tutorial -
Temps
Things to notice:
/* */ enclose comments – no
effect on program
Some but not all compilers accept
// for single line comments
3. Var declarations
Announce that fahr, etc, will be
names of pieces of data, of type int
floats)
chars
in an n-length field
main() {
int f;
for (f = LOWER; f <= UPPER;
f += STEP)
printf(“%3d %6.1f\n”, f,
(5.0/9)*(f–32));
}
putchar(c);
Prints char to screen/re-directed
file (>)
main() {
int c, i, nwhite, nother;
int ndigit[10];
nwhite = nother = 0;
for (i = 0; i < 10; i++)
ndigit[i] = 0;
int i, p;
p = 1;
for (i = 1; i <= n; ++i)
p *= b;
return p;
}