Monday, September 26, 2016

Week 4 PowerPoints


Code:
//
//  main.cpp
//  Sept26
//
//  Created by Mark Brautigam on 9/26/16.
//  Copyright © 2016 Mark Brautigam. All rights reserved.
//

#include <iostream>
#include <cmath>
using namespace std;

double pi = acos(-1.0);

double squareArea (double side) {
    return side * side;
}

double degrees2radians (double degrees) {
    return (degrees * pi / 180);
}

double radians2degrees (double radians) {
    return (radians * 180 / pi);
}

void getSideAndComputeArea () {
    cout << "Please enter the length of a side: ";
    double ui;
    cin >> ui;
    cout << "The area is " << squareArea (ui) << endl;
}

double rectangle (double w, double h) {
    return w * h;
}

double triangle (double a, double b, double c) {
    double s = (a + b + c) / 2;
    double t = s * (s-a) * (s-b) * (s-c);
    if (t < 0)
        ; // ...
    return sqrt (t); // <cmath>
}

long factorial (long n) {
    if (n <= 1)
        return 1;
    else
        return n * factorial (n-1);
}

long fibonacci (long n) {
    if (n <= 2)
        return 1;
    return fibonacci (n-1) + fibonacci (n-2);
}

int main(int argc, const char * argv[]) {
    // insert code here...
    
    cout << fibonacci (5) << endl;
    cout << fibonacci (6) << endl;
    cout << fibonacci (45) << endl;
    // cout << factorial (24.5) << endl;
    // cout << triangle(2, 12, 11) << endl;
    
    // getSideAndComputeArea();
    // getSideAndComputeArea();
    // getSideAndComputeArea();
    
    /*
     cout << squareArea (12) << endl;
    cout << degrees2radians(45) << endl;
    cout << radians2degrees(0.785398) << endl;
    
    double rad = degrees2radians(57);
    cout << rad << endl;
    cout << radians2degrees(rad) << endl;
    
    double x = 17;
    double y = 42;
    cout << rectangle (x, y) << endl;
     */
    return 0;
}



No comments:

Post a Comment