C - The C Answer (2nd Edition) - Exercise 1-5

/*
Modify the temperature conversion program to print the table in reverse order,
that is, from 300 degrees to 0.
*/

#include <stdio.h>

/* print Fahrenheit-Celsius table in reverse order */
main()
{
    int fahr;

    for(fahr = 300; fahr >= 0; fahr -= 20)
    {
    	printf("%3d %6.1f\n", fahr, (5.0 / 9.0) * (fahr - 32));
    }
}

/* Output:

300  148.9
280  137.8
260  126.7
240  115.6
220  104.4
200   93.3
180   82.2
160   71.1
140   60.0
120   48.9
100   37.8
 80   26.7
 60   15.6
 40    4.4
 20   -6.7
  0  -17.8
Press any key to continue . . .

*/

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-12 00:26:31

C - The C Answer (2nd Edition) - Exercise 1-5的相关文章

C - The C Answer (2nd Edition) - Exercise 1-18

/* Write a program to remove trailing blanks and tabs from each line of input, and to delete entirely blank lines. */ #include <stdio.h> #define MAXLINE 1000 /* maximum input line size */ int getline(char line[], int maxline); int remove(char s[]);

C - The C Answer (2nd Edition) - Exercise 1-19

/* Write a function reverse(s) that reverses the character string s. Use it to write a program that reverses its input a line at a time. */ #include <stdio.h> #define MAXLINE 1000 /* maximum input line size */ int getline(char line[], int maxline);

C - The C Answer (2nd Edition) - Exercise 1-4

/* Write a program to print the corresponding Celsius to Fahrenheit table. */ #include <stdio.h> /* print Celsius-Fahrenheit table for celsius = 0, 20, ..., 300; floating-point version */ main() { float fahr, celsius; int lower, upper, step; lower =

C - The C Answer (2nd Edition) - Exercise 1-7

/* Write a program to print the value of EOF. */ #include <stdio.h> main() { printf("EOF is %d\n", EOF); } /* Output: EOF is -1 */ 版权声明:本文为博主原创文章,未经博主允许不得转载.

C - The C Answer (2nd Edition) - Exercise 1-8

/* Write a program to count blanks, tabs, and newlines. */ #include <stdio.h> /* count blanks, tabs, and newlines */ main() { int c, nb, nt, nl; nb = 0; /* number of blanks */ nt = 0; /* number of tabs */ nl = 0; /* number of newlines */ while((c =

C - The C Answer (2nd Edition) - Exercise 1-9

/* Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank. */ #include <stdio.h> #define NONBLANK 'a' /* replace string of blanks with a single blank */ main() { int c, lastc; lastc = NONBLANK;

C - The C Answer (2nd Edition) - Exercise 1-10

/* Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and backspaces visible in an unambiguous way. */ #include <stdio.h> #define NONBLANK 'a' /* replace tabs an

C - The C Answer (2nd Edition) - Exercise 1-1

/* Run the "hello, world" program on your system. Experiment with leaving out parts of the program to see what error messages you get. */ #include <stdio.h> main() { printf("hello world\n"); } 版权声明:本文为博主原创文章,未经博主允许不得转载.

C - The C Answer (2nd Edition) - Exercise 1-2

/* Experiment to find out what happens when printf's argument string contains \c, where c is some character not listed above. */ #include <stdio.h> main() { printf("hello world\y"); printf("hello world\7"); printf("hello wor