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
15 changes: 15 additions & 0 deletions assignment5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Ava N.
July 5, 2016
Assignment 5

1. I would call int fxn(int a, float b, int c) by:
main(){
int a, c;
float b;
int fxn(int a, float b, int c)
return 0;
}

2. Recursion is when a function calls itself. Iteration is the repitition of a process or something, which can also be refered to as a loop. The best process to use, whether it is recursion or iteration depends on the circumstance. Iteration keeps going until the loop is complete while recursion solves a problem one at a time. Recursion is worse in other cases because it takes up more space and time...

3. A compiler works by taking 'High-level language' such as C, C++, and Java, and putting it through a compiler (gcc) to make an assembly.
Binary file added loop
Binary file not shown.
30 changes: 30 additions & 0 deletions loopFibonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*Ava N.*/
//fibonacci sequence as a loop
#include <stdio.h>
#include <math.h>

int main(){
int input;
int num1=0;
int num2=1;
int answer;
int counter;

printf("Enter the number of terms\n");
scanf("%d", &input);

printf("Here is the Fibonacci Sequence: \n");

for (counter=0; counter<input; counter++){
if (counter<=1){
answer=counter;
}
else{
answer=num1+num2;
num1=num2;
num2=answer;
}
printf("%d \n",answer);
}
return 0;
}
Binary file added recurse
Binary file not shown.
33 changes: 33 additions & 0 deletions recurseFibonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*Ava N.*/
//This is a program that uses a recursive function to print the first K Fibonacci numbers in sequence. In the Fibonacci sequence, each number is the sum of the 2 before it. The first 2 numbers in the sequence are 1.
#include <stdio.h>
#include <math.h>

int fibo(int K){
if ( K == 0 ){
return 0;
}
else if ( K == 1 ){
return 1;
}
else{
return (fibo(K-1) + fibo(K-2));
}
}

int main(){
int K;
int answer=0;
int counter;

printf("Type how long you want the fibanocci sequence to be: \n");
scanf("%d",&K);

printf("Here is the Fibonacci Sequence: \n");

for (counter=1 ; counter<= K ; counter++ ){
printf("%d\n", fibo(answer));
answer++;
}
}