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 + "です");
}
}
}
More than 5 years have passed since last update.
【c#】1週間分の体重データから最大値を求める例(float配列の最大値を求める)
Last updated at Posted at 2018-06-06
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
11