Jumpepy's Blog

C/C++のコード書いてます。入門を終えたら脆弱性攻撃やマルウェア解析関連のコード書きます。

華氏の温度と摂氏の温度の対応表を印字する 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!