「C やさしい入門」の版間の差分
ナビゲーションに移動
検索に移動
(ページの作成:「==C やさしい入門== [Programming C] {{amazon|4320026926}} ====hello world==== #include <stdio.h> int main() { printf("hello world\n"); } ====…」) |
|||
| (同じ利用者による、間の3版が非表示) | |||
| 1行目: | 1行目: | ||
| − | ==C やさしい入門== | + | ==[[C やさしい入門]]== |
| − | [Programming C] | + | [[Programming C]] | |
{{amazon|4320026926}} | {{amazon|4320026926}} | ||
====hello world==== | ====hello world==== | ||
| − | #include | + | #include <stdio.h> |
int main() | int main() | ||
| 13行目: | 13行目: | ||
====変数と算術式==== | ====変数と算術式==== | ||
摂氏、華氏対応表 | 摂氏、華氏対応表 | ||
| − | #include | + | #include <stdio.h> |
/* Convert temperature Celsius to Fahrenheit | /* Convert temperature Celsius to Fahrenheit | ||
F = 9/5 * C + 32 */ | F = 9/5 * C + 32 */ | ||
| 24行目: | 24行目: | ||
celsius = lower; | celsius = lower; | ||
| − | while (celsius | + | while (celsius <= upper) { |
fahren = celsius * 9 / 5 + 32; | fahren = celsius * 9 / 5 + 32; | ||
printf("%d\t%d\n", celsius, fahren); | printf("%d\t%d\n", celsius, fahren); | ||
| 33行目: | 33行目: | ||
====For文==== | ====For文==== | ||
摂氏、華氏対応表をForで書き直す | 摂氏、華氏対応表をForで書き直す | ||
| − | #include | + | #include <stdio.h> |
/* Convert temperature Celsius to Fahrenheit F = 9/5 * C + 32 */ | /* Convert temperature Celsius to Fahrenheit F = 9/5 * C + 32 */ | ||
int main() { int celsius; | int main() { int celsius; | ||
| − | for (celsius=0; celsius | + | for (celsius=0; celsius<=300; celsius +=20) { |
printf("%d\t%d\n", celsius, (celsius * 9 / 5 + 32)); | printf("%d\t%d\n", celsius, (celsius * 9 / 5 + 32)); | ||
} | } | ||
| 46行目: | 46行目: | ||
*セミコロン不要 | *セミコロン不要 | ||
| − | #include | + | #include <stdio.h> |
| − | #define | + | #define LOWE[[R]] 0 /* lower limit of temperature */ |
| − | #define | + | #define UPPE[[R]] 300 /* upper limit of temperature */ |
#define STEP 20 /* step size */ | #define STEP 20 /* step size */ | ||
| 57行目: | 57行目: | ||
int celsius; | int celsius; | ||
| − | for (celsius= | + | for (celsius=LOWE[[R]]; celsius<=UPPE[[R]]; celsius +=STEP) { |
printf("%d\t%d\n", celsius, (celsius * 9 / 5 + 32)); | printf("%d\t%d\n", celsius, (celsius * 9 / 5 + 32)); | ||
} | } | ||
} | } | ||
2020年2月16日 (日) 04:22時点における最新版
C やさしい入門
hello world
#include <stdio.h>
int main()
{
printf("hello world\n");
}
変数と算術式
摂氏、華氏対応表
#include <stdio.h>
/* Convert temperature Celsius to Fahrenheit
F = 9/5 * C + 32 */
int main()
{
int celsius; int fahren; int lower; int upper; int step;
lower = 0; /* lower limit of temperature */
upper = 300; /* upper limit of temperature */
step = 20;
celsius = lower;
while (celsius <= upper) {
fahren = celsius * 9 / 5 + 32;
printf("%d\t%d\n", celsius, fahren);
celsius = celsius + step;
}
}
For文
摂氏、華氏対応表をForで書き直す
#include <stdio.h>
/* Convert temperature Celsius to Fahrenheit F = 9/5 * C + 32 */
int main() { int celsius;
for (celsius=0; celsius<=300; celsius +=20) {
printf("%d\t%d\n", celsius, (celsius * 9 / 5 + 32));
}
}
記号定数
#define 名前 置き換えるテキスト
- セミコロン不要
#include <stdio.h> #define LOWER 0 /* lower limit of temperature */ #define UPPER 300 /* upper limit of temperature */ #define STEP 20 /* step size */ /* Convert temperature Celsius to Fahrenheit F = 9/5 * C + 32 */ int main() { int celsius; for (celsius=LOWER; celsius<=UPPER; celsius +=STEP) { printf("%d\t%d\n", celsius, (celsius * 9 / 5 + 32)); } }
© 2006 矢木浩人