strcpy()を使用したHello, world! in C
#include <stdio.h> #include <string.h> int main() { char str_a[20]; strcpy(str_a, "Hello, world!\n"); printf(str_a); }
Hello, world!
配列(バッファ)を使用したHello, world! in C
#include <stdio.h> int main() { char str_a[20]; str_a[0] = "H"; str_a[1] = "e"; str_a[2] = "l"; str_a[3] = "l"; str_a[4] = "o"; str_a[5] = ","; str_a[6] = " "; str_a[7] = "w"; str_a[8] = "o"; str_a[9] = "r"; str_a[10]= "l"; str_a[11]= "d"; str_a[12]= "!"; str_a[13]="\n"; str_a[14]= 0; printf(str_a); }
Hello, world!
華氏の温度と摂氏の温度の対応表を印字する in C
#include <stdio.h> int main() { int fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; fahr = lower; while (fahr <= upper) { celsius = 5 * (fahr-32) / 9; printf("%d\t%d\n", fahr, celsius); fahr = fahr + step; } }
0 -17 20 -6 40 4 60 15 80 26 100 37 120 48 140 60 160 71 180 82 200 93 220 104 240 115 260 126 280 137 300 148
Hello, world!を指定した回数出力 in C
#include <stdio.h> #include <string.h> int main() { char message[20]; int count, i; strcpy(message, "Hello, world!"); printf("何度繰り返しますか? "); scanf("%d", &count); for (i=0; i < count; i++) printf("%3d - %s\n", i+1, message); }
何度繰り返しますか? 10 1 - Hello, world! 2 - Hello, world! 3 - Hello, world! 4 - Hello, world! 5 - Hello, world! 6 - Hello, world! 7 - Hello, world! 8 - Hello, world! 9 - Hello, world! 10 - Hello, world!
December 28th
John von Neumann's birthday
エラトステネスの篩(ステップ2) in C
#include <stdio.h> int main() { int i; printf("2\n"); for (i=3; i<=10000; i++) printf("%d\n", i); return 0; }
エラトステネスの篩(ステップ1) in C
#include <stdio.h> int main() { int i; for (i=2; i<=10000; i++) { printf("%d\n", i); } return 0; }