LoginSignup
0
0

More than 5 years have passed since last update.

【C#】1週間分の体重データで軽い順にベスト3を表示する例

Posted at

using System;
// Listを使う際には以下を宣言する
using System.Linq;
using System.Collections.Generic;

namespace array_sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            //Listは簡単に並び替えができる
            //リスト名.Sort();で並び替えができる

            // 1週間分の体重データで軽い順にベスト3を表示する例

            // 1. List型の変数を作る
            //ここでは、リスト名:weights
            List<float> weights = new List<float>();

            // 2. Listに要素を追加する
            weights.Add(61.2f);
            weights.Add(51.2f);
            weights.Add(71.2f);
            weights.Add(54.2f);
            weights.Add(68.2f);
            weights.Add(61.3f);
            weights.Add(68.1f);
            weights.Add(64.3f);
            weights.Add(65.4f);
            // 例:weights[1] = 61.2f

            // 3. 小さい順に並び替える
            weights.Sort();

            // 4. for文で回す
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine(weights[i]);
            }
        }
    }
}


0
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
0
0