exercise 1.35 solution

#include <iostream>

using std::cout;
using std::endl;

int main() {
        cout << static_cast<int>('A') << endl;
        cout << static_cast<int>('B') << endl;
        cout << static_cast<int>('C') << endl;
        cout << static_cast<int>('a') << endl;
        cout << static_cast<int>('b') << endl;
        cout << static_cast<int>('c') << endl;
        cout << static_cast<int>('0') << endl;
        cout << static_cast<int>('1') << endl;

        return 0;
}

exercise 1.33 solution

#include <iostream>

using std::cout;
using std::endl;

int main() {
        cout << "* * * * * * * * " << endl
             << " * * * * * * * *" << endl
             << "* * * * * * * *" << endl
             << " * * * * * * * *" << endl
             << "* * * * * * * *" << endl
             << " * * * * * * * *" << endl
             << "* * * * * * * *" << endl
             << " * * * * * * * *" << endl;

        return 0;
}

exercise 1.32 solution

#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int main() {
        int number1, number2;

        cout << "Enter first number: ";
        cin >> number1;

        cout << endl << "Enter second number: ";
        cin >> number2;

        if(number1 % number2 == 0) {
                cout << number1 << " is multiple of " << number2 << endl;
        }else{
                cout << number1 << " is not multiple of " << number2 << endl;
        }

        return 0;
}

exercise 1.30 solution

#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int main() {
	int num1, num2, num3, num4, num5;

	cout << "Enter first integer: ";
	cin >> num1;

	cout << "\nEnter second integer: ";
	cin >> num2;

	cout << "\nEnter third integer: ";
	cin >> num3;

	cout << "\nEnter fourth integer: ";
	cin >> num4;

	cout << "\nEnter fifth integer: ";
	cin >> num5;

	int largest_num = num1;
	if(largest_num < num2) {
		largest_num = num2;
	}

	if(largest_num < num3) {
		largest_num = num3;
	}

	if(largest_num < num4) {
		largest_num = num4;
	}

	if(largest_num < num5) {
		largest_num = num5;
	}

	cout << "\nlargest number " << largest_num;

	int smallest_num = num1;
	if(smallest_num > num2) {
		smallest_num = num2;
	}

	if(smallest_num > num3) {
		smallest_num = num3;
	}

	if(smallest_num > num4) {
		smallest_num = num4;
	}

	if(smallest_num > num5) {
		smallest_num = num5;
	}

	cout << "\nsmallest number " << smallest_num << endl;

	return 0;
}

exericse 1.28 solution

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() {
	cout << "*********" << "\t" << "   ***   " << "    *    " << "    *    " << endl;
	cout << "*       *" << "\t" << " *     * " << "   ***   " << "   * *   " << endl;
	cout << "*       *" << "\t" << "*       *" << "  *****  " << "  *   *  " << endl;
	cout << "*       *" << "\t" << "*       *" << "    *    " << " *     * " << endl;
	cout << "*       *" << "\t" << "*       *" << "    *    " << "*       *" << endl;
	cout << "*       *" << "\t" << "*       *" << "    *    " << " *     * " << endl;
	cout << "*       *" << "\t" << "*       *" << "    *    " << "  *   *  " << endl;
	cout << "*       *" << "\t" << " *     * " << "    *    " << "   * *   " << endl;
	cout << "*********" << "\t" << "   ***   " << "    *    " << "    *    " << endl;

	return 0;
}

exercise 1.27 solution

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() {
	int radius;
	
	// prompt user to enter the radius
	cout << "Enter the radius: ";
	cin >> radius;

	int diameter = 2 * radius;
	int circum = 2 * radius * 3.14159;
	int area = 3.14159 * radius * radius;

	// display the results
	cout << "Diameter: " << diameter << endl;
	cout << "Circumference: " << circum << endl;
	cout << "Area: " << area << endl;

	return 0;
}

exercise 1.26 solution

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() {
	// store user input
	int num1, num2, num3;

	// prompt the user to enter 3 integer
	cout << "Input three different integers: ";
	cin >> num1 >> num2 >> num3;
	
	int sum = num1 + num2 + num3;
	int average = (num1 + num2 + num3) / 3;
	int product = num1 * num2 * num3;
	int largest;	

	if(num1 > average)
		largest = num1;
	else if(num2 > average)
		largest = num2;
	else
		largest = num3;

	int smallest;
	int median = (sum - largest) / 2;
	if(num1 < median)
		smallest = num1;
	else if(num2 < median)
		smallest = num2;
	else
		smallest = num3;

	cout << "Sum is " << sum << endl;
	cout << "Average is " << average << endl;
	cout << "Product is " << product << endl; 	
	cout << "Smallest is " << smallest << endl;		
	cout << "Largest is " << largest << endl;

	return 0;
}