練習用です。いろんなものがごちゃまぜです。
| @@ -1,12 +1,14 @@ | ||
| 1 | 1 | #include <stdio.h> |
| 2 | +#include <stdlib.h> | |
| 2 | 3 | |
| 3 | -int main(int argc, int argv[]) { | |
| 4 | +int main(int argc, char *argv[]) { | |
| 4 | 5 | if (argc != 2) { |
| 5 | 6 | printf("使用方法 2の2乗3乗4乗・・・表示する場合:%s 2\n", argv[0]); |
| 6 | 7 | return 1; |
| 7 | 8 | } |
| 8 | - int basenum = atoi(argv[1]); | |
| 9 | 9 | |
| 10 | + double basenum = atof(argv[1]); | |
| 11 | + | |
| 10 | 12 | if (-1 == basenum) { |
| 11 | 13 | //無限につづく |
| 12 | 14 | printf("-1 1 -1 1 -1 ・・・\n"); |
| @@ -21,14 +23,18 @@ | ||
| 21 | 23 | |
| 22 | 24 | if (-1 < basenum && basenum < 1){ |
| 23 | 25 | //だんだん小さくなる。 |
| 24 | - printf("%d", basenum); | |
| 25 | - return 1; | |
| 26 | + double pownum = basenum; | |
| 27 | + do { | |
| 28 | + printf("%f", pownum); | |
| 29 | + pownum *= basenum; | |
| 30 | + } while (pownum > 0.00000000000001); | |
| 31 | + return 0; | |
| 26 | 32 | } |
| 27 | 33 | |
| 28 | - int pownum = basenum; | |
| 34 | + double pownum = basenum; | |
| 29 | 35 | |
| 30 | 36 | while (pownum < 100000000) { |
| 31 | - printf("%d ", pownum); | |
| 37 | + printf("%0.0f ", pownum); | |
| 32 | 38 | pownum *= basenum; |
| 33 | 39 | } |
| 34 | 40 |