diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp | |
| download | Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2 | |
Diffstat (limited to 'Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp')
| -rw-r--r-- | Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp b/Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp new file mode 100644 index 0000000..03c35e7 --- /dev/null +++ b/Bachelor/Prog1/Prakt3/prg1p3_5/main.cpp @@ -0,0 +1,67 @@ +// Programmieren 1, Praktikum 3, Aufgabe 5
+// Sven Eisenhauer
+// 17.11.2004
+//
+// file: main.cpp
+//
+// purpose: egypt multiplication
+//
+//
+#include <iostream>
+using std::cin;
+using std::cout;
+using std::endl;
+
+int multIterative(int,int);
+void multRecursive(int,int, int &);
+
+int main()
+{
+ int number1,
+ number2,
+ erg;
+
+ cout << "1st number: ";
+ cin >> number1;
+ cout << "2nd number: ";
+ cin >> number2;
+
+ cout << "Product: " << multIterative(number1,number2) << endl;
+ multRecursive(number1,number2,erg);
+ cout << "Product: " << erg << endl;
+
+ return 0;
+}
+
+int multIterative(int a,int b)
+{
+ int product=0;
+ while (b>0)
+ {
+ if (0 != b%2)
+ product+=a;
+
+ a = a << 1;
+ b = b >> 1;
+ }
+ return product;
+}
+
+void multRecursive(int a,int b, int &product)
+{
+ int x,y;
+
+ if (b<=1)
+ product=a;
+
+ else
+ {
+ x=a<<1;
+ y=b>>1;
+ multRecursive(x,y,product);
+ if (0!=b%2)
+ product+=a;
+
+ }
+
+}
\ No newline at end of file |
