Exercise 5 solutions
Table of Contents
Python
e05.py
print "Fahrenheit", "Celsius", "C" for i in range(0,100,10): print "%10.2f %7.2f %6.2f" % (i, (i-32.)*5./9., (i-30)/2.0)
MATLAB / Octave
e05.m
disp(['Fahrenheit Celsius C']); for i=0:10:90 disp(sprintf('%10.2f %7.2f %6.2f', i, (i-32)*5/9, (i-30)/2)); end;
R
e05.R
cat("Fahrenheit", "Celsius", "C\n") for (i in seq(0,90,10)) { cat(sprintf("%10.2f %7.2f %6.2f\n", i, (i-32)*5/9, (i-30)/2)) }
C
e05.c
// compile with: gcc -o e05 e05.c #include <stdio.h> int main(int argc, char *argv[]) { printf("Fahrenheit Celsius C\n"); int i; for (i=0; i<=90; i+=10) { printf("%10.2f %7.2f %6.2f\n", (double) i, ((double)i-32)*5/9, ((double)i-30)/2); } return 0; }