Chapter 1, exercises 1.1, 1.2, and the beginning of 1.3
This commit is contained in:
parent
5524ab82a4
commit
f69b32679a
8 changed files with 64 additions and 0 deletions
BIN
1-1/hello
Executable file
BIN
1-1/hello
Executable file
Binary file not shown.
7
1-1/hello.c
Normal file
7
1-1/hello.c
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
printf("Hello world!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
1-1/hello1-2
Executable file
BIN
1-1/hello1-2
Executable file
Binary file not shown.
7
1-1/hello1-2.c
Normal file
7
1-1/hello1-2.c
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
printf("Hello world!\q");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
1-2/temperature
Executable file
BIN
1-2/temperature
Executable file
Binary file not shown.
25
1-2/temperature.c
Normal file
25
1-2/temperature.c
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Print a table of Fahrenheit temperatures and their Celsius equivalents.
|
||||||
|
* From K&R 2nd ed., 1-2
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
int fahr, celsius;
|
||||||
|
int lower, upper, step;
|
||||||
|
|
||||||
|
lower = 0; // Lower limit of temperature scale
|
||||||
|
upper = 300; // Upper limit of temperature scale
|
||||||
|
step = 20; // Step size
|
||||||
|
|
||||||
|
fahr = lower;
|
||||||
|
while (fahr <= upper) {
|
||||||
|
celsius = 5 * (fahr-32) / 9;
|
||||||
|
printf("%d\t%d\n", fahr, celsius);
|
||||||
|
fahr = fahr + step;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
BIN
1-2/temperature2
Executable file
BIN
1-2/temperature2
Executable file
Binary file not shown.
25
1-2/temperature2.c
Normal file
25
1-2/temperature2.c
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Print a table of Fahrenheit temperatures and their Celsius equivalents.
|
||||||
|
* From K&R 2nd ed., 1-2
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
int fahr, celsius;
|
||||||
|
int lower, upper, step;
|
||||||
|
|
||||||
|
lower = 0; // Lower limit of temperature scale
|
||||||
|
upper = 300; // Upper limit of temperature scale
|
||||||
|
step = 20; // Step size
|
||||||
|
|
||||||
|
fahr = lower;
|
||||||
|
while (fahr <= upper) {
|
||||||
|
celsius = 5 * (fahr-32) / 9;
|
||||||
|
printf("%3d %7d\n", fahr, celsius);
|
||||||
|
fahr = fahr + step;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue