LoginSignup
1
1

More than 5 years have passed since last update.

【c#】1週間分の体重データから最大値を求める例(float配列の最大値を求める)

Last updated at Posted at 2018-06-06

using System;

namespace maxweights
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            // 1週間分の体重データから最大値を求める例

            // 1. 配列を初期化
            float[] weights = { 61.2f, 62.5f, 64.9f, 63.2f, 65.1f, 63.2f, 65.1f, 63.2f, 62.7f };

            // 2. 最も重い体重を記憶する変数"max"を用意
            float max = 0.0f;
            // 3. 1週間の体重を順に参照
            for (int i = 0; i < weights.Length; i++)
            {
                // 4. maxの値が現在記録している体重よりも重ければ更新
                if (weights[i] > max)
                {
                    max = weights[i];
                }
            }
            // 5. 出力
            Console.WriteLine("最大値は" + max + "です");
        }
    }
}

1
1
4

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
1