ex1-1.c
/* code: ex1-1.c (v1.20.00) */
#include <stdio.h>
int main () {
printf ("The Open University of Japan\n");
return 0;
}
ex1-2.c
/* code: ex1-2.c (v1.20.00) */
#include <stdio.h>
int main () {
int a;
printf ("Enter an integer: ");
scanf ("%d", &a);
printf ("The integer you entered was %d.\n", a);
return 0;
}
ex1-3.c
/* code: ex1-3.c (v1.20.00) */
#include <stdio.h>
int main () {
char a;
short b;
int c;
long d;
float e;
double f;
printf ("char: %zd byte(s)\n", sizeof (a));
printf ("short: %zd byte(s)\n", sizeof (b));
printf ("int: %zd byte(s)\n", sizeof (c));
printf ("long: %zd byte(s)\n", sizeof (d));
printf ("float: %zd byte(s)\n", sizeof (e));
printf ("double: %zd byte(s)\n", sizeof (f));
return 0;
}
ex1-4.c
/* code: ex1-4.c (v1.20.00) */
#include <stdio.h>
int main () {
int a, b, c;
a = 10;
b = 3;
c = 0;
printf ("a=%d\n", a);
printf ("b=%d\n\n", b);
c = a + b;
printf ("a + b = %d\n", c);
c = a - b;
printf ("a - b = %d\n", c);
c = a * b;
printf ("a * b = %d\n", c);
c = a / b;
printf ("a / b = %d\n", c);
c = a % b;
printf ("a %% b = %d\n", c);
return 0;
}
ex1-5.c
/* code: ex1-5.c (v1.20.00) */
#include <stdio.h>
#include <math.h>
int main () {
double x, y, z;
x = 30.0;
y = 3.0;
z = 0.0;
printf ("x=%f\n", x);
printf ("y=%f\n\n", y);
z = pow (x, y);
printf ("pow(x,y) = %f\n", z);
return 0;
}
ex1-6.c
/* code: ex1-6.c (v1.20.00) */
#include <stdio.h>
#include <math.h>
int main () {
float celsius, fahrenheit;
celsius = 36.5;
fahrenheit = (9.0 / 5.0) * celsius + 32.0;
printf ("%f(Celsius) = %f(Fahrenheit)\n", celsius, fahrenheit);
return 0;
}
ex1-7.c
/* code: ex1-7.c (v1.20.00) */
#include <stdio.h>
int main () {
printf ("The Open University of Japan\n");
/* web address
http://www.ouj.ac.jp/ */
// C++ style comments
// C99 allows single-line comments
return 0;
}
q1-1.c
/* code: q1-1.c (v1.20.00) */
#include <stdio.h>
#include <math.h>
int main () {
double x, y;
x = 3.14159;
y = 0.0;
printf ("x=%f\n\n", x);
y = ceil (x);
printf ("ceil(x) = %f\n", y);
y = floor (x);
printf ("floor(x) = %f\n", y);
return 0;
}
q1-2.c
/* code: q1-2.c (v1.20.00) */
#include <stdio.h>
#include <math.h>
int main () {
float fx, fz;
double dx, dz;
long double lx, lz;
fx = 100.00F;
fz = sqrtf (fx);
printf ("fx = %f\n", fx);
printf ("sqrtf(fx) = %f\n\n", fz);
dx = 100.00;
dz = sqrt (dx);
printf ("dx = %f\n", dx);
printf ("sqrt(dx) = %f\n\n", dz);
lx = 100.00L;
lz = sqrtl (lx);
printf ("lx = %Lf\n", lx);
printf ("sqrtl(lx) = %Lf\n\n", lz);
return 0;
}
q1-3.c
/* code: q1-3.c (v1.20.00) */
#include <stdio.h>
#include <math.h>
int main () {
float fahrenheit, celsius;
fahrenheit = 25.1;
celsius = (5.0 / 9.0) * (fahrenheit - 32.0);
printf ("%f(Fahrenheit) = %f(Celsius)\n", fahrenheit, celsius);
return 0;
}
EOF