トップ 一覧 ping 検索 ヘルプ RSS ログイン

C やさしい入門の変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
!!!C やさしい入門
[Programing C]
[Programming C]
{{amazon 4320026926}}

!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));
   }
 }