fahr1.c

/*
 * FAHR1 -- program to print Fahrenheit temperatures between 0 and 
 * 300, counting by 20s, and the corresponding centigrade 
 * temperaures
 *
 * Usage: fahr1
 *
 * Inputs: none
 * Output: table of temperatures, as above
 * Exit Code: EXIT_SUCCESS (0) because all goes well
 *
 * Matt Bishop, Sept. 24, 2015
 *	original program written
 */
#include <stdio.h>
#include <stdlib.h>

/*
 *  main routine
 *
 * print a table for Fahrenheit to Celsius
 * from 0 F to 300 F
 */
int main(void)
{
	int fahr;			/* fahrenheit temperature */
	int celsius;			/* celsius temperature */
	register int lower = 0;		/* begin table here */
	register int upper = 300;	/* end table here */
	register int step = 20;		/* increment */

	/*
	 * print out the lines for the table
	 */
	/* print the header */
	printf("deg F\tdeg C\n");
	/* print the values */
	fahr = lower;
	while(fahr <= upper){
		/* get corresponding temp in degrees C */
		celsius = 5 * (fahr - 32) / 9;
		/* print it */
		printf("%d\t%d\n", fahr, celsius);
		fahr += step;
	}

	/*
	 * say goodbye
	 */
	exit(EXIT_SUCCESS);
}

UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: [email protected]
ECS 36A, Programming & Problem Solving
Version of April 4, 2024 at 3:10PM

You can get the raw source code here.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh