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. + 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 + +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