Converted everything to orgmode
converted everything to orgmode and added solution to the README files
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
# Task
|
||||
|
||||
Write a program that performs the binary expansion for a given decimal input number $x$, where $0 \leq x < 2$. Use the algorithm presented in the lecture. The program must output the first $16$ digits of the number in the format: $b_0, b_1, b_2, ... , b_15$.
|
||||
|
||||
_Important_ Always print all $16$ digits, even the trailing zeros. Do not normalize or round the number.
|
||||
|
||||
You can structure your program into functions to avoid code repetition. Do not forget to annotate functions with pre- and post conditions.
|
47
Informatik_I/Exercise_4/Task_4/README.org
Normal file
47
Informatik_I/Exercise_4/Task_4/README.org
Normal file
@@ -0,0 +1,47 @@
|
||||
#+TITLE: Task 4: Binary Expansion
|
||||
#+AUTHOR: JirR02
|
||||
|
||||
* Task
|
||||
|
||||
Write a program that performs the binary expansion for a given decimal input number \(x\), where \(0 \leq x < 2\). Use the algorithm presented in the lecture. The program must output the first \(16\) digits of the number in the format: \(b_0, b_1, b_2, ... , b_15\).
|
||||
|
||||
/Important/ Always print all \(16\) digits, even the trailing zeros. Do not normalize or round the number.
|
||||
|
||||
You can structure your program into functions to avoid code repetition. Do not forget to annotate functions with pre- and post conditions.
|
||||
|
||||
* Solution
|
||||
|
||||
#+begin_src cpp
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
|
||||
float i;
|
||||
int n;
|
||||
float d;
|
||||
|
||||
std::cin >> i;
|
||||
|
||||
if (i < 0 || i > 2)
|
||||
return 0;
|
||||
else {
|
||||
n = i;
|
||||
d = i - n;
|
||||
|
||||
std::cout << n << ".";
|
||||
|
||||
n = d;
|
||||
d = 2 * (d - n);
|
||||
|
||||
for (int j = 1; j <= 15; ++j) {
|
||||
n = d;
|
||||
d = 2 * (d - n);
|
||||
std::cout << n;
|
||||
}
|
||||
}
|
||||
}
|
||||
#+end_src
|
||||
|
||||
-----
|
||||
|
||||
Made by JirR02 in Switzerland 🇨🇭
|
@@ -1,28 +0,0 @@
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
|
||||
float i;
|
||||
int n;
|
||||
float d;
|
||||
|
||||
std::cin >> i;
|
||||
|
||||
if (i < 0 || i > 2)
|
||||
return 0;
|
||||
else {
|
||||
n = i;
|
||||
d = i - n;
|
||||
|
||||
std::cout << n << ".";
|
||||
|
||||
n = d;
|
||||
d = 2 * (d - n);
|
||||
|
||||
for (int j = 1; j <= 15; ++j) {
|
||||
n = d;
|
||||
d = 2 * (d - n);
|
||||
std::cout << n;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user