Problem Exercises Chapter 03

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

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

View Full Document Right Arrow Icon
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 :
Background image of page 1

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

View Full DocumentRight Arrow Icon
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;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online