- 
                Notifications
    You must be signed in to change notification settings 
- Fork 20
completed assignment 5 #12
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
          
     Open
      
      
            yaelkelmer
  wants to merge
  1
  commit into
  CPRO-Session1:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
yaelkelmer:master
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Yael Kelmer. | ||
|  | ||
| 1. This is how you would call the function inside of the main() function: | ||
|  | ||
| int main () { | ||
|  | ||
| int a = 1; /* this initializes a value for a */ | ||
| float b = 2.5; /* this initializes a value for b */ | ||
| int c = 4; /* this initializes a value for c */ | ||
|  | ||
| int fxn (a, b, c); /* this calls the function fxn and uses the arguments that were initialized */ | ||
| } | ||
|  | ||
| 2. The difference between recursion and iteration is that recursion is recursive and iteration goes step by step. In terms of runtime, iteration is preferable, because it will take much less time than a recursion. In terms of lines of code, recursion will take less lines of code, so in that sense it would be preferable to use recursion. However, recursion is so slow that the extra lines of code are worth it. | ||
| 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. but what is recursion? and how about memory usage? which is better? | ||
|  | ||
|  | ||
| 3. A compiler reads the human-readable, high-level language and converts it to assembly, which is the lowest level language. | ||
| 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! | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* Yael Kelmer. | ||
| This code prompts the user for the amount of elements of the Fibonacci series that they would like to see and the code uses a loop to give those numbers. */ | ||
|  | ||
| #include <stdio.h> | ||
|  | ||
| int main () { | ||
|  | ||
| printf ("Please type the amount of numbers of the Fibonacci series that you would like to see:\n"); | ||
| int numberOfElements; | ||
| scanf ("%d", &numberOfElements); | ||
|  | ||
| int i; | ||
| int n; | ||
| int n1 = 1; | ||
| int n2 = 1; | ||
|  | ||
| printf ("This is the first %d elements in the Fibonacci series\n", numberOfElements); | ||
| if (numberOfElements == 1) { | ||
| printf ("%d\n", n2); | ||
| } | ||
| else { | ||
| printf ("%d\n%d\n", n2, n1); | ||
| } | ||
| for (i = 0; i < numberOfElements - 2; i++) { | ||
| n = n1 + n2; | ||
| n2 = n1; | ||
| n1 = n; | ||
| printf ("%d\n", n); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* Yael Kelmer. | ||
| This code prompts the user for the amount of elements of the Fibonacci series that they would like to see and the code uses a recursion to give those numbers. */ | ||
|  | ||
| #include <stdio.h> | ||
|  | ||
| /*This was my second attempt at fixing the code, but this printed all of the duplicate values that get calculated in the recursive calls. */ | ||
| /*int x; | ||
| int numberInSeries; | ||
| int fib (int x) { | ||
| if (x == 1) { | ||
| printf ("1\n"); | ||
| return 1; | ||
| } | ||
| if (x == 2) { | ||
| printf ("1\n"); | ||
| return 1; | ||
| } | ||
| else { | ||
| numberInSeries = fib (x-1) + fib (x-2); | ||
| printf ("%d\n", numberInSeries); | ||
| return numberInSeries; | ||
| } | ||
| }*/ | ||
|  | ||
| /* this is my final code and it works! */ | ||
| int sum; | ||
| int fib(int x, int y, int z, int i) { | ||
| if (i >= z) { | ||
| return; | ||
| } | ||
| sum = x + y; | ||
| printf ("%d\n", sum); | ||
| return fib (y, x+y, z, i+1); | ||
|  | ||
| } | ||
|  | ||
| int main () { | ||
| int z; | ||
| printf ("Please type the amount of numbers in the Fibonacci series that you would like to see\n"); | ||
| scanf ("%d", &z); | ||
|  | ||
| printf ("This is the first %d elements in the Fibonacci series\n", z); | ||
| printf ("1\n1\n"); | ||
| fib (1, 1, z, 2); | ||
|  | ||
| /* This was my first attempt at printing all of the values for the Fibonacci series, but it was inefficient, so I tried another code. */ | ||
| /*int i; | ||
| int numberInSeries; | ||
| printf ("This is the Fibonacci series:"); | ||
| for (i = 1; i <= x; i++) { | ||
| numberInSeries = fib (i); | ||
| printf ("%d ", numberInSeries); | ||
| } | ||
| printf ("\n");*/ | ||
| } | ||
|  | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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.
right! but make sure that the function is declared before the main function to avoid a warning.