From cec5b44875f1986b3fe18b7e4270acddea64ac35 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 5 Jul 2016 18:00:47 -0400 Subject: [PATCH 1/4] Completed Text File --- assignment5.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 assignment5.txt diff --git a/assignment5.txt b/assignment5.txt new file mode 100644 index 0000000..47119dc --- /dev/null +++ b/assignment5.txt @@ -0,0 +1,10 @@ +Jack Rosen +1. int main() { + int a = 0, c = 0; + float b; + fxn(a,b,c); + return 0; +} +My code would look like this. I would instantiate the variables and then call the function. +2. An iteration uses loops to continue going but a recursion calls itself to keep it going. There are times where iteration can take longer and times where recursion can use up more storage. Recursion can be worst because if it is endless because it keeps taking up more space. +3. A compiler changes the code from the high-level language to assembly. It checks the whole code for syntax errors and will alert you of the errors. From af3a89e4707b0417827df80c5118b67f6b4a54a9 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 5 Jul 2016 18:03:41 -0400 Subject: [PATCH 2/4] Fibonacci sequence with loops --- loopFibonacci.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 loopFibonacci.c diff --git a/loopFibonacci.c b/loopFibonacci.c new file mode 100644 index 0000000..beaf373 --- /dev/null +++ b/loopFibonacci.c @@ -0,0 +1,15 @@ +#include + +int main() +{ + int answer = 0, amount, incrementer = 1; + printf("How many numbers do you want in the array?\n"); + scanf("%d", &amount); + for (; amount > 0; amount--) + { + answer += incrementer; + incrementer = answer - incrementer; + printf("%d\n", answer); + } + return 0; +} From cffcddcdd433b521f450d9d54416f3548c2fdc3c Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 5 Jul 2016 18:04:05 -0400 Subject: [PATCH 3/4] Fibonacci sequence with recursion --- recurseFibonacci.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 recurseFibonacci.c diff --git a/recurseFibonacci.c b/recurseFibonacci.c new file mode 100644 index 0000000..604f16e --- /dev/null +++ b/recurseFibonacci.c @@ -0,0 +1,21 @@ +#include +int fibonacci(int i, int K) +{ + static int x = 0; + if (K == 0) + { + return 0; + } + x += i; + i = x - i; + printf("%d\n", x); + return fibonacci(i, K - 1); +} +int main() +{ + int amount, input = 1; + printf("How many numbers would you want in the sequence?\n"); + scanf("%d", &amount); + fibonacci(input, amount); + return 0; +} From bdc0b61a62af41bd9a85f6d6dfc6e3427c7fdfe5 Mon Sep 17 00:00:00 2001 From: jrosen081 Date: Tue, 5 Jul 2016 18:05:31 -0400 Subject: [PATCH 4/4] Update loopFibonacci.c --- loopFibonacci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopFibonacci.c b/loopFibonacci.c index beaf373..1d9b827 100644 --- a/loopFibonacci.c +++ b/loopFibonacci.c @@ -1,5 +1,5 @@ #include - +/* Jack Rosen. The purpose of this code is to do the Fibonacci sequence with loops*/ int main() { int answer = 0, amount, incrementer = 1;