Created
April 17, 2014 01:44
-
-
Save ktnyt/10947438 to your computer and use it in GitHub Desktop.
フィボナッチ with C
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 <ライブラリ名.h> ってやるとライブラリを使える。 | |
** stdioとstdlibがあれば大抵できるけど他にもほしくなるケースもあるよ。 | |
** int main() っていうのも定型文で、メインの処理をここに書くよ。 | |
** ※だからmainっていう名前なのね。 | |
** int argcとchar** argvはコマンドライン引数って言うよ。 | |
** コンパイルしたあとに実行するときに | |
** ./hoge 10 20 みたいにするとスペースで区切られた文字列が入ってるよ。 | |
** テンプレここから *********************************************************** | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char** argv) { | |
return 0; | |
} | |
** ここまで ******************************************************************* | |
*/ | |
// というわけでここからコード... | |
#include <stdio.h> | |
#include <stdlib.h> | |
// 今回は引数が必要ないので | |
int main() { | |
int i, x, y; | |
// 初期値 | |
x = 0; | |
y = 1; | |
for(i = 0; i < 30; ++i) { | |
printf("%d:\t%d\n", i + 1, x); | |
y = x + y; | |
x = y - x; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment