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. diff --git a/loopFibonacci.c b/loopFibonacci.c new file mode 100644 index 0000000..1d9b827 --- /dev/null +++ b/loopFibonacci.c @@ -0,0 +1,15 @@ +#include +/* Jack Rosen. The purpose of this code is to do the Fibonacci sequence with loops*/ +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; +} 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; +}