Last active
          December 17, 2015 11:39 
        
      - 
      
- 
        Save ozw-sei/5603481 to your computer and use it in GitHub Desktop. 
    fibo
  
        
  
    
      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
    
  
  
    
  | #include <stdio.h> | |
| int main(int argc, const char * argv[]) | |
| { | |
| //forのカウンタ | |
| int i = 0; | |
| //buffer | |
| int prev_num = 0; | |
| int prev2_num = 0; | |
| int current_num = 0; | |
| //入力検出 | |
| unsigned int input = 0; | |
| printf("n項を入力してください。"); | |
| scanf("%d",&input); | |
| for(i = 1;i<input +1;i++){ | |
| // 項数が2以下の場合 | |
| if(i <= 2){ | |
| prev_num = 1; | |
| prev2_num = 1; | |
| current_num = 1; | |
| }else{ | |
| prev2_num = prev_num; | |
| prev_num = current_num; | |
| current_num = prev_num + prev2_num; | |
| } | |
| printf("現在値=%d",current_num); | |
| } | |
| return 0; | |
| } | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
current_num無くてもいいな