十七课

一、

try

{

Console.WriteLine("请输入6个数字");

int[] nums = new int[6];

for (int i = 0; i < nums.Length; i++)

{

Console.WriteLine("请输入第{0}个数字:", i + 1);

nums[i] = Convert.ToInt32(Console.ReadLine());

}

for (int i = 0; i < nums.Length - 1; i++)

{

for (int j = 0; j < nums.Length - 1 - i; j++)

{

if (nums[j] < nums[j+1])

{

int temp = nums[j];

nums[j] = nums[j + 1];

nums[j + 1] = temp;

}

}

}

Console.Write("排序后的数字为:");

foreach (double var in nums

{

Console.Write(var);

Console.Write(" ");

}

}

catch

{

Console.WriteLine("你输入的格式有误");

}

Console.ReadKey();

二、

try

{

Console.WriteLine("请输入会员本月的消费记录");

double[] mon = new double [5];

double sum = 0;

for (int i = 0; i < mon.Length; i++)

{

Console.WriteLine("");

Console.WriteLine("请输入第{0}笔消费金额:", i + 1);

mon[i] = Convert.ToDouble(Console.ReadLine());

}

for (int i = 0; i

{

Console.WriteLine("序号\t\t\t金额(元)");

Console.WriteLine("{0}\t\t\t{1}",i+1,mon[i]);

sum += mon[i];

}

Console.WriteLine("总金额\t\t\t" +sum);

}

catch

{

Console.WriteLine("你输入的格式有误");

}

Console.ReadKey();

你可能感兴趣的:(十七课)