-
Notifications
You must be signed in to change notification settings - Fork 20
Jack Rosen, Assignment 5 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
| 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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
| 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; | ||
| } |
| 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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
There was a problem hiding this comment.
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!