Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions assignment5.txt
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I actually forgot to check for your method declaration!

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, complexity is key! and now that we're learning about memory management, you can further understand this by understanding that each time a function is called, a stack is initialized. So having a recursive function can be very memory ineffective.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! Specifically, the compiler breaks up the text of your program into tokens, which are then converted to a part tree. From there, a compiler optimizes for unused variables, unreachable code, etc. Once this is done, the parse tree is converted into machine instructions!

15 changes: 15 additions & 0 deletions loopFibonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
/* 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;
}
21 changes: 21 additions & 0 deletions recurseFibonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>
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;
}