開発環境
- OS: macOS High Sierra - Apple
- IDE(統合開発環境): Visual Studio for Mac
- プログラミング言語: C#
初めてのC# 第2版 (Jesse Liberty (著)、Brian MacDonald (著)、日向 俊二 (翻訳)、オライリージャパン)の10章(配列)、10.9(練習問題)、問題10-2.を取り組んでみる。
コード
using System;
namespace Sample10_2
{
class Program
{
static void Main(string[] args)
{
int n = 10;
int[] nums = new int[n];
for (int i = 0; i < n; i++)
{
Console.Write(">> ");
string s = Console.ReadLine();
int m = int.Parse(s);
nums[i] = m;
}
Array.Sort(nums);
Array.Reverse(nums);
foreach (int num in nums)
{
Console.WriteLine(num);
}
}
}
}
入出力結果(Terminal)
>> 10 >> 1 >> 9 >> 2 >> 8 >> 3 >> 7 >> 4 >> 6 >> 5 10 9 8 7 6 5 4 3 2 1 Press any key to continue...
0 コメント:
コメントを投稿