1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Arduino UNO 3でサイコロの期待値(平均)を求めて遊ぶ

Posted at

目的
合計から割り算して平均(期待値)求める
サイコロの期待値は、3.5が正解
小数点がないので、切り捨てで3
いちお、高校レベルらしい

いろいろ
アルゴリズムの教科書では、
ドラクエ1的に言ったらレベル55+で真ん中ぐらい
いろいろ違うが、乗り物に乗れるレベル

●なんじゃー

o_coq394.jpg

結果

o_coq395.jpg

プログラム



//heikin_UNO_1

//初期化
// the setup routine runs once when you press reset:
void setup() {

  //シリアルポートの初期化
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

}//setup



#define n 6

//メインループ
// the loop routine runs over and over again forever:
void loop() {

  int x[n + 1];

  x[1] = 1; x[2] = 2; x[3] = 3; x[4] = 4; x[5] = 5; x[6] = 6;

  //合計を求める
  int z = 0; int a;
  for (int k = 1; k <= n; k++) {

    z = z + x[k];

  }//for

  //合計を総数で割って平均を求める
  a = z / n;

  //結果の表示
  // print out the value you a:
  Serial.println(a);
  delay(1000);        // delay in between reads for stability

}//loop


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?