0% found this document useful (0 votes)
49 views7 pages

Programming 1: COMP 208

This document summarizes Chapter 5 of a programming textbook. It discusses math functions in math.h, finding and correcting errors in code segments, function headers, and implementing integer functions to convert between Celsius and Fahrenheit temperatures. It provides examples of function headers and code to write a program that prints conversion charts between the two temperature scales.

Uploaded by

Adham Y
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views7 pages

Programming 1: COMP 208

This document summarizes Chapter 5 of a programming textbook. It discusses math functions in math.h, finding and correcting errors in code segments, function headers, and implementing integer functions to convert between Celsius and Fahrenheit temperatures. It provides examples of function headers and code to write a program that prints conversion charts between the two temperature scales.

Uploaded by

Adham Y
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Programming 1

COMP 208
Chapter 5

Math.h
• pow(x,y)

• sqrt(x)

• Abs(x)

2
Chapter 5
Find the error in each of the following program segments and
explain how the error can be corrected:

• int g( void ) {
printf( "Inside function g\n" );
int h( void ) {
printf( "Inside function h\n" );
}
}

• int sum(int x,int y)


{
int result;
result = x + y;
}

3
Chapter 5

• void f( float a ); {
float a;
printf( "%f", a );
}

• void product( void ) {


int a, b, c, result;
printf( "Enter three integers: " );
scanf( "%d%d%d", &a, &b, &c );
result = a * b * c;
printf( "Result is %d", result );
return result;
}

4
Chapter 5

Give the function header for each of the following functions.

• Function hypotenuse that takes two double-precision floating-point arguments,


side1 and side2, and returns a double-precision floating-point result.

• Function smallest that takes three integers, x, y, z, and returns an integer.

• Function instructions that does not receive any arguments and does not return a
value.

• Function intToFloat that takes an integer argument, number, and returns a


floating-point result.

5
Chapter 5
Implement the following integer functions:

• Function Celsius returns the Celsius equivalent of a


Fahrenheit temperature.
Hint: Tc = 5 / 9 x ( Tf - 32 )

• Function Fahrenheit returns the Fahrenheit equivalent of a Celsius


temperature.
Hint: Tf = 9 / 5 x Tc + 32

• Use these functions to write a program that prints charts showing


the Fahrenheit equivalents of all Celsius temperatures from 0 to 100
degrees, and the Celsius equivalents of all Fahrenheit temperatures
from 32 to 212 degrees. Print the outputs in a neat tabular format
that minimizes the number of lines of output while remaining
readable.
6

You might also like