From 98b18ffb5801940c1fa63e0ddfff67f26a3ec3ec Mon Sep 17 00:00:00 2001 From: Sheqi Date: Wed, 6 Jul 2016 09:22:39 -0400 Subject: [PATCH 1/3] recursion --- recursionFibonacci.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 recursionFibonacci.c diff --git a/recursionFibonacci.c b/recursionFibonacci.c new file mode 100644 index 0000000..cd9f246 --- /dev/null +++ b/recursionFibonacci.c @@ -0,0 +1,22 @@ +#include + +long int fibonacci(int n){ + if(n==0) + return 1; + else if(n==1) + return 1; + else + return fibonacci(n-1)+fibonacci(n-2); +} + + +int main(){ + int n,i=0,a; + printf("Please type in a number:\n"); + scanf("%d",&n); + for(a=0;a Date: Wed, 6 Jul 2016 09:40:52 -0400 Subject: [PATCH 2/3] loop --- loopFibonacci.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 loopFibonacci.c diff --git a/loopFibonacci.c b/loopFibonacci.c new file mode 100644 index 0000000..dc22fde --- /dev/null +++ b/loopFibonacci.c @@ -0,0 +1,19 @@ +#include + +int main(){ + int n,c; + printf("Please type in a number:\n"); + scanf("%d",&n); + int fibonacci[n]; + for(c=0;c Date: Wed, 6 Jul 2016 09:52:56 -0400 Subject: [PATCH 3/3] Assignment5 --- Assignment5 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Assignment5 diff --git a/Assignment5 b/Assignment5 new file mode 100644 index 0000000..505ec47 --- /dev/null +++ b/Assignment5 @@ -0,0 +1,16 @@ +Assignment 5 Sheqi Zhang +1. How would you call the following function? Give an example of what it would look like written inside of the main() function and explain your code in detail. + +``` + int fxn(int a, float b, int c) +``` +Answer: +int call = fxn(a,b,c) + +2. Explain the difference between recursion and iteration. When/why is one preferable over the other? Why is recursion worse in other cases? +Answer: +Recursion is the function that call itself. Iteration is a repitition of process. Recursion is short and simple, while iteration is faster, and also takes less memory. + +3. How does a compiler work? Explain step by step. +A compiler translates the high-level programming language like c to excutable code, which can be read by the computer. It first break up the text into "tokens", then converse these tokens into parse tree. Next, it evaluate constant expressions, and finally, it translate the parse tree into machine instructions. +