aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Strapp <msattr@gmail.com>2019-02-20 15:10:20 -0600
committerMatthew Strapp <msattr@gmail.com>2019-02-20 15:10:20 -0600
commite3f772edd868d3c4995856904d24eac28b550bd9 (patch)
tree85dce38e4d66075149a169208b23a954da126548
parentAdd MATLAB hw check script (diff)
downloadhomework-e3f772edd868d3c4995856904d24eac28b550bd9.tar
homework-e3f772edd868d3c4995856904d24eac28b550bd9.tar.gz
homework-e3f772edd868d3c4995856904d24eac28b550bd9.tar.bz2
homework-e3f772edd868d3c4995856904d24eac28b550bd9.tar.lz
homework-e3f772edd868d3c4995856904d24eac28b550bd9.tar.xz
homework-e3f772edd868d3c4995856904d24eac28b550bd9.tar.zst
homework-e3f772edd868d3c4995856904d24eac28b550bd9.zip
(Screams internally)
Diffstat (limited to '')
-rw-r--r--ee1301/wk3/lab3/RtBab.cpp43
-rw-r--r--ee1301/wk3/lab3/multTable.cpp16
2 files changed, 36 insertions, 23 deletions
diff --git a/ee1301/wk3/lab3/RtBab.cpp b/ee1301/wk3/lab3/RtBab.cpp
index d60beda..d75bd9e 100644
--- a/ee1301/wk3/lab3/RtBab.cpp
+++ b/ee1301/wk3/lab3/RtBab.cpp
@@ -2,22 +2,35 @@
#include <cmath>
using namespace std;
-double genNewGuess(double n, double oldGuess); {
- New=(oldGuess+n/oldGuess)/2;
- oldGuess=New;
- return New;
+double gennewGuess(double n, double old_guess) {
+ bool WA=true;
+ double real, old;
+ //if (WA) {
+ real=sqrt(n);
+ WA=false;
+ //}
+ double new_guess = ( old_guess + n / old_guess ) / 2;
+ old=new_guess;
+ if (((new_guess-real)/real)>0.01) {
+ cout << old << endl;
+ return gennewGuess(n, old);
+ } else {
+ cout << old << endl;
+ return new_guess;
+ }
}
int main () {
- double temp;
+ double temp, temp2;
cout << "Enter the Number to find square root: ";
- cin >> n;
- if (n==0) {
- cout << "Nah fam." << endl;
- return -1
+ cin >> temp;
+ if (temp<=0) {
+ cout << "Please enter a valid input(Positive Integer)." << endl;
+ return -1;
}
- cout << "Guessing..."
- double real=sqrt(n);
- do {
-
- } (while abs(New-real)/real<0.1)
-} \ No newline at end of file
+ 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/multTable.cpp b/ee1301/wk3/lab3/multTable.cpp
index 5201c07..8e2e887 100644
--- a/ee1301/wk3/lab3/multTable.cpp
+++ b/ee1301/wk3/lab3/multTable.cpp
@@ -1,18 +1,18 @@
#include <iostream>
using namespace std;
int main() {
- int row=1, column=1;
- for (row; row<=10; row++) {
- for (column=10; column>0; column--) {
- int temp = row*column;
- if (temp!=100) {
+ int r=1, c=1;
+ for (r; r<=10; r++) {
+ for (c=10; c>0; c--) {
+ int ans = r*c;
+ if (ans!=100) {
cout << " ";
}
- if (temp<10) {
+ if (ans<10) {
cout << " ";
}
- cout << temp;
+ cout << ans;
}
cout << endl;
}
-} \ No newline at end of file
+}