Learn faster and stay on-track by joining this free class with other self-learners.
|
Programming in CClass length: 8 weeks. Start anytime. Creator: kday Status: Established |
Join this class! |
Lesson 1: Assignment 2: Variables and Arithmetic Expressions.Complete Exercise 1-3 and Exercise 1-4 on page 13. Homework Submissions19 total#include <stdio.h>
int main ()
/* temperature table with headings for fahrenheit and celsius. Used int for this exercise */
{
int fahr, celcius;
int lower, upper, step;
lower = 0; /* low limit of table */
upper = 300; /* upper limit of table */
step = 20; /* size of step */
fahr = lower;
printf("Fahrenheit to Celsius Conversion Table\n\n");
printf("fahrenheit\tcelsius\n"); /* headings */
while (fahr <= upper) {
celcius = 5 * (fahr - 32) /9;
printf("%d\t\t%d\n", fahr, celcius); /* tab to align header with data */
fahr = fahr + step;
}
}
#include <stdio.h>
/* Exercise 1.4. */
main ()
/* celsius to fahrenheit conversion table with headers */
{
float fahr, celsius;
int lower, upper, step;
lower = -20; /* low limit of table */
upper = 150; /* upper limit of table */
step = 10; /* size of step 10 degrees C */
celsius = lower;
printf("Table: Celsius to Fahrenheit conversions\n\n"); /*table head */
printf("Cel\tFahr\n-------------\n"); /* headings */
while (celsius <= upper) {
fahr = (celsius * 9.0/5.0) + 32;
printf("%3.0f\t%6.1f\n", celsius, fahr);
celsius = celsius + step;
}
}
ans:1-3;
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("fahrenheit-celsius table");
for(a=0;a<=300;a=+20);
printf("%3d %6.1f\n",a,(5.0/9.0)*(a-32);
getch();
}
No comments. Sign up or log in to comment /* 1-3 */
#include <stdio.h>
/* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */
main()
{
int fahr, celsius;
int lower, upper, step;
lower = 0; /* lower limit of temperature scale */
upper = 300; /* upper limit */
step = 20; /* step size */
fahr = lower;
printf("-------------------------------------------\n");
printf(" Fahrenheit-Celsius Table \n");
printf("-------------------------------------------\n");
printf(" Fahrenheit\tCelsius\n");
while (fahr <= upper)
{
celsius = 5 * (fahr-32) / 9;
printf("%d\t\t%d\n", fahr, celsius);
fahr = fahr + step;
}
}
/* 1-4 */
#include <stdio.h>
/* print Celsius-Fahrenheit table for celsius = -40, -20, ..., 100 */
main()
{
int fahr, celsius;
int lower, upper, step;
lower = -40; /* lower limit of temperature scale */
upper = 100; /* upper limit */
step = 20; /* step size */
celsius = lower;
printf("-------------------------------------------\n");
printf(" Celsius-Fahrenheit Table \n");
printf("-------------------------------------------\n");
printf(" Celsius\tFahrenheit\n");
while (celsius <= upper)
{
fahr = 9 * celsius / 5 + 32;
printf("%d\t\t%d\n", celsius, fahr);
celsius = celsius + step;
}
}
No comments. Sign up or log in to comment #include <stdio.h>
main()
{
float fahr, celcius;
int lower, upper, step;
lower = 0; // lower limit of temp table
upper = 300; //upper limit
step = 20; // stepsize
printf("Fahrenheit\tCelsius\n");
fahr=lower;
while(fahr<=upper) {
celcius = (5.0/9.0) * (fahr-32);
printf("%f\t%f\n", fahr, celcius);
fahr = fahr + step;
}
}
/*_____________________
Fahrenheit Celsius
0.000000 -17.777779
20.000000 -6.666667
40.000000 4.444445
60.000000 15.555555
80.000000 26.666666
100.000000 37.777779
120.000000 48.888889
140.000000 60.000000
160.000000 71.111115
180.000000 82.222221
200.000000 93.333336
220.000000 104.444443
240.000000 115.555557
260.000000 126.666664
280.000000 137.777771
300.000000 148.888885
______________________*/
#include <stdio.h>
main()
{
float fahr, celcius;
int lower, upper, step;
lower = 0; // lower limit of temp table
upper = 300; //upper limit
step = 20; // stepsize
printf("Celsius \t Fahrenheit\n");
celcius=lower;
while(celcius<=upper) {
fahr = (5.0/9.0) * (celcius+32);
printf("%f\t%f\n", celcius,fahr);
celcius = celcius + step;
}
}
/*___________________
output for 1.4
Celsius Fahrenheit
0.000000 17.777779
20.000000 28.888889
40.000000 40.000000
60.000000 51.111111
80.000000 62.222221
100.000000 73.333336
120.000000 84.444443
140.000000 95.555557
160.000000 106.666664
180.000000 117.777779
200.000000 128.888885
220.000000 140.000000
240.000000 151.111115
260.000000 162.222229
280.000000 173.333328
300.000000 184.444443
_____________________*/
No comments. Sign up or log in to comment Ex1-3 tempconv.c
1 #include <stdio.h>
2
3 /*print fahrenheit-celsius table */
4
5 /* F = (9/5)*C+32 & C = (F-32) * (5/9) */
6
7 int main(){
8
9 float fahr, celsius;
10 int lower, upper, step;
11
12 lower = 0;
13 upper = 200;
14 step = 20;
15
16 fahr = lower;
17 system("clear"); //linux bash shell screen clear function
18 printf("Temperature Conversion Chart\n");
19 printf("Fahrenheit\tCelsius\n");
20 while ( fahr <= upper ){
21 celsius = (fahr-32.0) * (5.0/9.0);
22 printf("%10.2f\t%7.2f\n",fahr,celsius);
23 fahr = fahr + step;
24 }
25 }
ex1-4
tempconv1.c
3 /*print fahrenheit-celsius table */
4
5 /* F = (9/5)*C+32 & C = (F-32) * (5/9) */
6
7 int main(){
8
9 float fahr, celsius;
10 int lower, upper, step;
11
12 lower = -20;
13 upper = 100;
14 step = 10;
15
16 celsius = lower;
17 system("clear"); //linux bash shell screen clear function
18 printf("Temperature Conversion Chart\n");
19 printf("Celsius\tFahrenheit\n");
20 while ( celsius <= upper ){
21 fahr = (9.0/5.0*celsius) + 32.0;
22 printf("%7.2f\t%10.2f\n",celsius,fahr);
23 celsius = celsius + step;
24 }
25 }
No comments. Sign up or log in to comment # 1-3
#include <stdio.h>
/*
* Print Fahrenheit-Celcius table
*/
main()
{
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
printf("Fahrenheit\tCelcius\n=======================\n");
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr - 32.0);
printf("%10.0f\t%6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
~/code/c/kr/chap1 $ gcc fahr_celcius.c -o farcel
~/code/c/kr/chap1 $ ./farcel
Fahrenheit Celcius
=======================
0 -17.8
20 -6.7
40 4.4
60 15.6
80 26.7
100 37.8
120 48.9
140 60.0
160 71.1
180 82.2
200 93.3
220 104.4
240 115.6
260 126.7
280 137.8
300 148.9
# 1-4
#include <stdio.h>
/*
* Print celsius-Fahrenheit table
*/
main()
{
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
celsius = lower;
printf("Celsius\tFahrenheit\n=======================\n");
while (celsius <= upper) {
fahr = (9.0/5.0) * celsius + 32.0; // (5.0/9.0) * (fahr - 32.0);
printf("%6.0f\t%10.1f\n", celsius, fahr);
celsius = celsius + step;
}
}
~/code/c/kr/chap1 $ gcc celcius_fahr.c -o celfar
~/code/c/kr/chap1 $ ./celfar
Celsius Fahrenheit
=======================
0 32.0
20 68.0
40 104.0
60 140.0
80 176.0
100 212.0
120 248.0
140 284.0
160 320.0
180 356.0
200 392.0
220 428.0
240 464.0
260 500.0
280 536.0
300 572.0
No comments. Sign up or log in to comment #include "stdio.h"
int main()
{
//start F->C
printf("Fahrenheit - to - Celsius\n\n");
float fahr, cel;
float min=0 , max=200, step=20;
fahr = min;
while (fahr <= max)
{
cel = (5.0/9.0) * (fahr-32.0);
printf("%3.f\t\t%6.1f\n", fahr, cel);
fahr = fahr + step;
}
//start C->F
printf("\n\nCelsius - to - Fahrenheit \n\n");
min=0 , max=200, step=20;
cel = min;
while (cel <= max)
{
fahr = cel/(5.0/ 9.0)+32.0 ;
printf("%3.f\t\t%6.1f\n", cel, fahr);
cel = cel + step;
}
return(0);
No comments. Sign up or log in to comment Exercise 1-3Added the line: printf(" C Fn==========n"); Exercise 1-4
// Exercise 1-3
#include <stdio.h>
// print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300
int main() {
float fahr, celsius;
float lower, upper, step;
lower = 0; // lower limit of temperature scale
upper = 300; // upper limit
step = 20; // step size
printf(" F C\n==========\n");
fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
// Exercise 1-4
#include <stdio.h>
// print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300
int main() {
float fahr, celsius;
float lower, upper, step;
lower = 0; // lower limit of temperature scale
upper = 300; // upper limit
step = 20; // step size
printf(" C F\n==========\n");
celsius = lower;
while (celsius <= upper) {
fahr = celsius/(5.0/9.0) + 32.0;
printf("%6.1f %3.0f\n", celsius, fahr);
celsius = celsius + step;
}
}
No comments. Sign up or log in to comment /*
* Programming in C
* Exercise 1-3
*
* Date:
* 05/02/2011
*
* Description:
* Displays a Fehrenheit-Celsius table
* from 0 - 300 degrees
*
* Build:
* gcc temp.c
*/
#include <stdio.h>
main()
{
float fahr, celsius;
int lower, upper, step;
lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */
/* table heading */
printf("Fehrenheit\tCelsius\n");
int ndx; /* index used for iterating in header loops */
ndx = 0;
while(ndx < 25)
{
printf("_");
ndx += 1;
}
printf("\n"); /* finish the previous line with with a line feed*/
/* print the table */
fahr = lower;
while(fahr <= upper) {
celsius = (5.0 / 9.0) * (fahr - 32);
printf("%3c%3.0f%10c%6.1f\n", ' ', fahr, ' ', celsius);
fahr = fahr + step;
}
}
/*
* Programming in C
* Exercise 1-4
*
* Date:
* 05/02/2011
*
* Description:
* Displays a Celsius-Fehrenheit table
* from 0 - 300 degrees
*
* Build:
* gcc temp.c
*/
#include <stdio.h>
main()
{
float fahr, celsius;
int lower, upper, step;
lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */
/* table heading */
printf("Celsius%8cFehrenheit\n", ' ');
int ndx; /* index used for iterating in header loops */
ndx = 0;
while(ndx < 25)
{
printf("_");
ndx += 1;
}
printf("\n"); /* finish the previous line with with a line feed*/
/* print the table */
celsius = lower;
while(celsius <= upper) {
fahr = 32.0 + (9.0 / 5.0) * celsius;
printf("%3c%3.0f%10c%6.1f\n", ' ', celsius, ' ', fahr);
celsius = celsius + step;
}
}
No comments. Sign up or log in to comment Using "while" loops only and no functions it's kind of dirty but it works. /* Exercise 1-3
*
* Description:
* Modify the temperature conversion program to print a heading above
* the table.
*
* Date: 03/29/2011
*
*/
#include <stdio.h>
int main(void)
{
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
// print header
int count = 0;
while (count < 25)
{
// print asterisk
putchar('*');
count++;
}
putchar('\n');
// print program name
printf("Temperature Conversion\n");
// print a divder
count = 0;
while (count < 25)
{
putchar('-');
count++;
}
putchar('\n');
printf("Fahrenheit\tCelsius\n");
count=0;
while (count < 25)
{
// print asterisk
putchar('*');
count++;
}
putchar('\n');
fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f\t\t%6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
/* Exercise 1-4
*
* Description:
* Write a program to print the corresponding Celsius to Fahrenheit table.
*
* Date: 03/29/2011
*
*/
#include <stdio.h>
int main(void)
{
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
// print header
int count = 0;
while (count < 25)
{
// print asterisk
putchar('*');
count++;
}
putchar('\n');
// print program name
printf("Temperature Conversion\n");
// print a divder
count = 0;
while (count < 25)
{
putchar('-');
count++;
}
putchar('\n');
printf("Celsius\tFahrenheit\n");
count=0;
while (count < 25)
{
// print asterisk
putchar('*');
count++;
}
putchar('\n');
fahr = lower;
while (fahr <= upper) {
fahr = (celsius * (9/5)) + 32;
printf("%3.0f\t\t%6.1f\n", celsius, fahr);
celsius = celsius + step;
}
}
No comments. Sign up or log in to comment For the 1-4 exercise, I didn't just reverse the printing of the columns, I ran Celsius from 0 - 300. Exercise 1-3 - Heading
#include <stdio.h>
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */
main()
{
float fahr, celsius;
float lower, upper, step;
printf("\nFahrenheit to Celsius Conversion table\n\n");
lower = 0; /* lower limit of temperature scale */
upper = 300; /* upper limit */
step = 20; /* step size */
fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f\t%6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
Fahrenheit to Celsius Conversion table
0 -17.8
20 -6.7
40 4.4
60 15.6
80 26.7
100 37.8
120 48.9
140 60.0
160 71.1
180 82.2
200 93.3
220 104.4
240 115.6
260 126.7
280 137.8
300 148.9
Exercise 1-4 - Celsius to Fahrenheit table.
#include <stdio.h>
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */
main()
{
float fahr, celsius;
float lower, upper, step;
printf("\nCelsius to Fahrenheit Conversion table\n\n");
lower = 0; /* lower limit of temperature scale */
upper = 300; /* upper limit */
step = 20; /* step size */
celsius = lower;
while (celsius <= upper) {
fahr = ((9.0/5.0) * celsius)+32.0;
printf("%3.0f\t%6.1f\n", celsius, fahr);
celsius = celsius + step;
}
}
Celsius to Fahrenheit Conversion table
0 32.0
20 68.0
40 104.0
60 140.0
80 176.0
100 212.0
120 248.0
140 284.0
160 320.0
180 356.0
200 392.0
220 428.0
240 464.0
260 500.0
280 536.0
300 572.0
No comments. Sign up or log in to comment sample output 1-4
Farenheight Celcius
0 -17.78
20 -6.67
40 4.44
60 15.56
80 26.67
100 37.78
120 48.89
140 60.00
160 71.11
180 82.22
200 93.33
220 104.44
240 115.56
260 126.67
280 137.78
sample output 1-3
Celcius Farenheight
--------------------------------
0 57.60
2 61.20
4 64.80
6 68.40
8 72.00
10 75.60
12 79.20
14 82.80
16 86.40
18 90.00
20 93.60
22 97.20
24 100.80
26 104.40
28 108.00
30 111.60
32 115.20
34 118.80
36 122.40
38 126.00
40 129.60
/*exercise 1-3*/
#include <stdio.h>
#define upper 300
#define lower 0
#define step 20
main()
{
int faren;
printf("Farenheight\tCelcius\n");
for( faren = lower;faren < upper; faren = faren + step)
{
printf("%6d \t\t %6.2f\n", faren, (5.0/9.0)*(faren-32));
}
}
/* exercise 1-4*/
#include <stdio.h>
#define upper 42
#define lower 0
#define step 2
main()
{
float faren;
int cel;
printf("Celcius \t Farenheight\n");
printf("--------------------------------\n");
for(cel = lower;cel < upper;cel+=step)
{
faren = (9.0/5.0)*(cel+32);
printf("%6d \t\t %6.2f\n",cel,faren);
}
}
No comments. Sign up or log in to comment #include <stdio.h>
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */
main()
{
printf("Fahrenheit to Celsius Conversion Table\n\n");
printf("F\xF8\tC\xF8\n\n");
float fahr, celsius;
float 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.0/9.0) * (fahr - 32.0);
printf("%3.0f\t%6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
No comments. Sign up or log in to comment /*** Excercise 1-3 ***/
#include <stdio.h>
main()
{
float fahr, celsius;
float lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
printf("\n------------------------------------");
printf("\n--- CONVERT CELSIUS 2 FAHRENHEIT ---");
printf("\n------------------------------------\n");
printf("\n F C°\n");
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
/*** Excercise 1-4 ***/
#include <stdio.h>
main()
{
float fahr, celsius;
float lower, upper, step;
lower = 0;
upper = 150;
step = 10;
fahr = lower;
printf("\n------------------------------------");
printf("\n--- CONVERT FAHRENHEIT 2 CELSIUS ---");
printf("\n------------------------------------\n");
printf("\n C° F\n");
while (celsius <= upper) {
fahr = ((celsius*9.0)/5.0)+32.0;
printf("%3.0f %6.0f\n", fahr, celsius);
celsius = celsius + step;
}
}
No comments. Sign up or log in to comment Below are my codes for Exercise 1-3 and 1-4. For exercise 1-4 I took the conversion the 3 decimals place. //Exercise 1-3
#include <stdio.h>
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */
main()
{
float fahr, celsius;
float lower, upper, step;
lower = 0; /* lower limit of temperature scale */
upper = 300; /* upper limit */
step = 20; /* step size */
fahr = lower;
printf("Fahrenheit to Celsius Conversion Table\n\n");
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f\t%6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
//Exercise 1-4
#include <stdio.h>
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */
main()
{
float fahr, celsius;
float lower, upper, step;
lower = 0; /* lower limit of temperature scale */
upper = 300; /* upper limit */
step = 20; /* step size */
celsius = lower;
printf("Celsius to Fahrenheit Conversion Table\n\n");
while (celsius <= upper) {
fahr = (9.0/5.0) * celsius+32.0;
printf("%3.0f\t%6.3f\n", celsius, fahr);
celsius = celsius + step;
}
}
No comments. Sign up or log in to comment Here are my codes. That is it for today for me. Including the reading, it took me probably about 40 mins to do it, but not including it, probably around 20, do I said 30 to be fair. 1.3
#include<stdio.h>
/*print Fahrenheit-Celsius table
for fahr = 0.20,...,300; floating-point version*/
int main(void)
{
printf("Fahrenheit to Celsius!"); /*Sorry about the exclaimation point, but I am excited*/
printf("Fahrenheit\tCelsius\n");
float fahr,celsius;
int lower, upper, step;
lower = 0; /*lower limit size*/
upper = 300;/*upper limit*/
step = 20; /*step size*/
fahr = lower;
while (fahr <= upper){
celsius = (5.0/9.0)*(fahr-32.0);
printf("%3.0f\t\t%6.3f\n", fahr, celsius);
fahr = fahr + step;
}
return 0;
}
1.4 /*Dear god I am so proud of this one! Little things make me happy*/
#include<stdio.h>
int main(void){
printf("Celsius\t\tFahrenheit\n");
float celsius, fahr;
int lower, upper, step;
lower = -15;
upper = 100;
step = 5;
celsius = lower;
while (celsius <= upper){
fahr = ((9.0/5.0)*celsius)+32;
printf("%.0f\t\t%.2f\n",celsius,fahr);
celsius = celsius + step;
}
return 0;
}
No comments. Sign up or log in to comment 1.3:
#include <stdio.h>
/* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300; floating-point version */
main() {
float fahr, celsius; float lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
printf("A Farenheit to Celsius conversion table\n");
printf("%3s %6s\n", "°F", "°C");
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
1.4:
#include <stdio.h>
/* print Celsius-Fahrenheit table for celsius = -20, -10, ..., 150; floating-point version */
main() {
float fahr, celsius; float lower, upper, step;
lower = -20;
upper = 150;
step = 10;
celsius = lower;
printf("A Celsius to Fahrenheit conversion table\n");
printf("%3s %6s\n", "°C", "°F");
while (celsius <= upper) {
fahr = ((9.0/5.0) * celsius)+32.0;
printf("%3.0f %6.0f\n", celsius, fahr);
celsius = celsius + step;
}
}
#1.4 Sample output:
#A Celsius to Fahrenheit conversion table
#°C °F
#-20 -4
#-10 14
# 0 32
# 10 50
# 20 68
# 30 86
# 40 104
# 50 122
# 60 140
# 70 158
# 80 176
# 90 194
#100 212
#110 230
#120 248
#130 266
#140 284
#150 302
No comments. Sign up or log in to comment We're still in simple C territory here; watch your floats and your order of operations. #exercise 1.3
#include <stdio.h>
main()
{
float fahr, celsius;
float lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
printf("Degrees F | Degrees C\n");
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf(" %3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
#Output:
#Degrees F | Degrees C
# 0 -17.8
# 20 -6.7
# 40 4.4
# 60 15.6
# 80 26.7
# 100 37.8
# 120 48.9
# 140 60.0
# 160 71.1
# 180 82.2
# 200 93.3
# 220 104.4
# 240 115.6
# 260 126.7
# 280 137.8
# 300 148.9
#Exercise 1.4
#include <stdio.h>
main()
{
float fahr, celsius;
float lower, upper, step;
lower = -20.0;
upper = 160;
step = 20;
celsius = lower;
printf("Degrees C | Degrees F\n");
while (celsius <= upper) {
fahr = (celsius * (9.0/5.0)) + 32;
printf(" %6.0f %3.1f\n", celsius, fahr);
celsius = celsius + step;
}
}
#Output:
#Degrees C | Degrees F
# -20 -4.0
# 0 32.0
# 20 68.0
# 40 104.0
# 60 140.0
# 80 176.0
# 100 212.0
# 120 248.0
# 140 284.0
# 160 320.0
No comments. Sign up or log in to comment # Exercise 1-3
#include <stdio.h>
/* print Farenheight-Celsius table
for fahr = 0, 20, ..., 300 */
main()
{
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
printf(" C F\n----------\n");
while(fahr <= upper){
celsius = (5.0/9.0) * (fahr-32.0) ;
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
# Exercise 1-4
#include <stdio.h>
/* print Celsius-Farenheight table
for celsius = -20, -10, 0 ..., 150 */
main()
{
float fahr, celsius;
int lower, upper, step;
lower = -20;
upper = 150;
step = 10;
celsius = lower;
printf(" F C\n----------\n");
while(celsius <= upper){
fahr = 32.0 + (9.0/5.0) * celsius;
printf("%3.0f %6.1f\n", celsius, fahr);
celsius = celsius + step;
}
}
No comments. Sign up or log in to comment |
No comments. Sign up or log in to comment