Skip to content

Instantly share code, notes, and snippets.

@ozw-sei
Last active December 17, 2015 11:39
Show Gist options
  • Save ozw-sei/5603481 to your computer and use it in GitHub Desktop.
Save ozw-sei/5603481 to your computer and use it in GitHub Desktop.
fibo
#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;
}
@ozw-sei
Copy link
Author

ozw-sei commented May 18, 2013

current_num無くてもいいな

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment