aboutsummaryrefslogtreecommitdiff
path: root/semestre 3/architecture des ordinateurs/tme/tme2/exo3/q1.c
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-09-26 12:24:19 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-09-26 12:24:19 +0200
commit9cb070097ebf4692ae2bcb23e854a3e4ffdccd53 (patch)
treec55c348daa1d1c1c34529a9d6c4e6f209f9a1a7b /semestre 3/architecture des ordinateurs/tme/tme2/exo3/q1.c
parent7ed2d38e36518873139d5fea9b977e9ae72e7838 (diff)
Cours du 22 au 26 septembre
Diffstat (limited to 'semestre 3/architecture des ordinateurs/tme/tme2/exo3/q1.c')
-rw-r--r--semestre 3/architecture des ordinateurs/tme/tme2/exo3/q1.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/semestre 3/architecture des ordinateurs/tme/tme2/exo3/q1.c b/semestre 3/architecture des ordinateurs/tme/tme2/exo3/q1.c
new file mode 100644
index 0000000..cac5209
--- /dev/null
+++ b/semestre 3/architecture des ordinateurs/tme/tme2/exo3/q1.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+float suite(int n){
+ if (n == 0) return 1;
+ return 2*suite(n-1)+1;
+}
+
+unsigned long long int suiteInt(int n){
+ if (n==0) return 1;
+ return 2*suiteInt(n-1)+1;
+}
+
+int main(){
+ float val = 1;
+ int i;
+ for (i = 0; i < 129 && val > 0; i++) {
+ val = suite(i);
+ printf("%d — %f\n", i, val);
+ printf("%d — %llu\n", i, suiteInt(i));
+ }
+ /* Le code déborde à partir de 127 avec la valeur "inf"
+ * À partir du 24, la suite devient impaire à cause d'un manque de précision des floats
+ * */
+}