diff options
Diffstat (limited to 'ee1301/wk3')
| -rw-r--r-- | ee1301/wk3/lab3/RootBabylonOG.cpp | 3 | ||||
| -rw-r--r-- | ee1301/wk3/lab3/fib.cpp | 14 | ||||
| -rw-r--r-- | ee1301/wk3/lab3/gcd.cpp | 25 | ||||
| -rw-r--r-- | ee1301/wk3/lab3/primeFactor.cpp | 21 | ||||
| -rw-r--r-- | ee1301/wk3/lab3/strap012_lab3_decimal_roman_conv.cpp | 71 | 
5 files changed, 100 insertions, 34 deletions
| diff --git a/ee1301/wk3/lab3/RootBabylonOG.cpp b/ee1301/wk3/lab3/RootBabylonOG.cpp index 07c1951..e97ff49 100644 --- a/ee1301/wk3/lab3/RootBabylonOG.cpp +++ b/ee1301/wk3/lab3/RootBabylonOG.cpp @@ -16,7 +16,7 @@ double gennewGuess(double n, double old_guess) {    }  }  int main () { -  double temp, temp2; +  double temp;    cout << "Enter the Number to find square root: ";    cin >> temp;    if (temp<=0) { @@ -25,7 +25,6 @@ int main () {    }    cout << "Guessing..." << endl;    double real=sqrt(temp); -  temp2=temp;    temp = gennewGuess(temp, 1.0);    cout << "The Final Guess: " << temp << endl     << "Actual Value: " << real << endl; diff --git a/ee1301/wk3/lab3/fib.cpp b/ee1301/wk3/lab3/fib.cpp index cd3a048..67ba8bb 100644 --- a/ee1301/wk3/lab3/fib.cpp +++ b/ee1301/wk3/lab3/fib.cpp @@ -2,14 +2,18 @@  using namespace std;  int main()  { -  unsigned long long fib1=0, fib2=1, count, temp; +  unsigned long long fib1=0, fib2=1, count, fib3=1;    cout << "How many Fibonacci numbers should be computed? ";    cin >> count; +  bool firstRun=true;    for (int i=1; i<(count+1); i++) { -    temp=fib1+fib2; -    fib1=fib2; -    fib2=temp; -    cout << temp << " "; +    if (!firstRun) { //The contents are run when i is not 1. +      fib3=fib1+fib2; +      fib1=fib2; +      fib2=fib3; +    } +    firstRun=false; +    cout << fib3 << " ";      if (i%10==0 && i!=0)        cout << endl;    } diff --git a/ee1301/wk3/lab3/gcd.cpp b/ee1301/wk3/lab3/gcd.cpp new file mode 100644 index 0000000..435fd07 --- /dev/null +++ b/ee1301/wk3/lab3/gcd.cpp @@ -0,0 +1,25 @@ +#include <iostream> +#include <cmath> +using namespace std; + +int GCD(int a, int b) { +  int gcd=0; +  a=abs(a); b=abs(b); +  if (a>b) { +    //do nothing +  } else { +    if (b>a) { +     int foo=a; a=b; b=foo; +   } else { +      return 1; +    } +  } +  gcd=(a/b)+(a%b); +  return gcd; +} +int main () { +  int a=0, b=0; +  cout << "Enter two integers: "; +  cin >> a, b; +  cout << GCD(a,b) << endl; +} diff --git a/ee1301/wk3/lab3/primeFactor.cpp b/ee1301/wk3/lab3/primeFactor.cpp new file mode 100644 index 0000000..1ec5bcc --- /dev/null +++ b/ee1301/wk3/lab3/primeFactor.cpp @@ -0,0 +1,21 @@ +#include <iostream> +#include <iomanip> +#include <cmath> +using namespace std; +int primefinder (long long n) { +  for (long long i=n; i>1; --i) { + +      if (n%i==0 && n!=i) { +        primefinder(i); +        cout << i << "*"; +      } +    } +    return composite; +} +int main () { +  long long n; +  cout << "Input a positive integer:  "; +  cin >> n; +  primefinder(n); +  cout << endl; +} diff --git a/ee1301/wk3/lab3/strap012_lab3_decimal_roman_conv.cpp b/ee1301/wk3/lab3/strap012_lab3_decimal_roman_conv.cpp index 6dbd3bc..1049063 100644 --- a/ee1301/wk3/lab3/strap012_lab3_decimal_roman_conv.cpp +++ b/ee1301/wk3/lab3/strap012_lab3_decimal_roman_conv.cpp @@ -1,41 +1,58 @@ +//Matthew Strapp +//5449340 +//20 February 2018 +//Lab 3 Workout +  #include <iostream> -#include <string>  using namespace std;  int main () {    int decimal;    cout << "Enter an integer value from 1 to 999: ";    cin >> decimal; -  if (decimal<1||decimal>999) { +  if (decimal<1 || decimal>999) {      cout << "       Invalid Input.    Program terminated." << endl;      return 1453;    } else {        cout << "Roman numeral equivalent: ";    while (decimal!=0) { -    if (decimal>900 && decimal<1000) { -      cout << "CM"; decimal-=900; } -    if (decimal>500 && decimal<900) { -      cout << "D"; decimal-=500; } -    if (decimal>400 && decimal<500) { -      cout << "CD"; decimal-=400; } -    if (decimal>100 && decimal<400) { -      cout << "C"; decimal-=100; } -    if (decimal>90 && decimal<100) { -      cout << "XC"; decimal-=90; } -    if (decimal>50 && decimal<90) { -      cout << "L"; decimal-=50; } -    if (decimal>40 && decimal<50) { -      cout << "XL"; decimal-=40; } -    if (decimal>10 && decimal<40) { -      cout << "X"; decimal-=10; } -    if (decimal==9) { -      cout << "IX"; decimal-=9; } -    if (decimal>5 && decimal<9) { -    cout << "V"; decimal-=5; } -    if (decimal==4) { -    cout << "IV"; decimal-=4; } -    if (decimal>=1 && decimal<4) { -    cout << "I"; decimal-= 1; } -  }} +      if (decimal>900 && decimal<1000) { +        cout << "CM"; decimal-=900; +        } +      if (decimal>=500 && decimal<900) { +        cout << "D"; decimal-=500; +        } +      if (decimal>=400 && decimal<500) { +        cout << "CD"; decimal-=400; +        } +      if (decimal>=100 && decimal<400) { +        cout << "C"; decimal-=100; +        } +      if (decimal>=90 && decimal<100) { +        cout << "XC"; decimal-=90; +        } +      if (decimal>=50 && decimal<90) { +        cout << "L"; decimal-=50; +        } +      if (decimal>=40 && decimal<50) { +        cout << "XL"; decimal-=40; +        } +      if (decimal>=10 && decimal<40) { +        cout << "X"; decimal-=10; +        } +      if (decimal==9) { +        cout << "IX"; decimal-=9; +        } +      if (decimal>=5 && decimal<9) { +        cout << "V"; decimal-=5; +        } +      if (decimal==4) { +        cout << "IV"; decimal-=4; +        } +      if (decimal>=1 && decimal<4) { +        cout << "I"; decimal-= 1; +        } +      } +    }    cout << endl;    return 0;  } | 
