Problem Exercises Chapter 03

# Problem Exercises Chapter 03 - Problem Exercises Chapter 03...

This preview shows pages 1–3. Sign up to view the full content.

Problem Exercises Chapter 03 1 Problem Exercises 1. Page 232: Exercise 28. Write a function that returns the smallest of three double-precision, floating-point numbers. #include <iostream.h> double smallest( double , double , double ); int main() { double x, y, z; cout << "Enter three numbers: "; cin >> x >> y >> z; cout << "The smallest value is: " << smallest(x, y, z) << endl << endl; return 0; } double smallest( double smallest, double b, double c) { if (b < smallest) smallest = b; if (c < smallest) smallest = c; return smallest; } Sample Output :

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Problem Exercises Chapter 03 2 2. Page 232: Exercise 29. An integer is said to be a perfect number if the sum of its factors, including 1 (but not the number itself), is equal to the number. For example, 6 is a perfect number, because 6 = 1 + 2 + 3. Write a function that determines whether a number is perfect. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. #include <iostream.h> bool perfect( int ); int main() { cout << "For the integers from 1 to 1000: \n"; for ( int j = 2; j <= 1000; ++j) if ( perfect(j) ) cout << j << " is perfect \n"; cout << endl;
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 9

Problem Exercises Chapter 03 - Problem Exercises Chapter 03...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online