You are on page 1of 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