…
作业1
…
步骤:
1.定义数组存储价格,并利用循环输入。
2.定义变量min保存当前的最低价。
- 将min和数组中的其余元素依次比较。
…
代码
…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] money = new int[4];
Console.WriteLine("请输入4家店的价格:");
int i;
for (i = 0; i < money.Length; i++)
{
Console.Write("第{0}店的价格:", i + 1);
money[i] = Convert.ToInt32(Console.ReadLine());
}
int temp = 0;
for (int a= 1; a < money.Length; a++)
{
if (money[a] < money[a - 1])
{
temp = a;
}
}
int min = money[temp];
Console.Write("最低价是:{0}", min);
Console.ReadKey();
}
}
}
…
效果
…
![](https://img.haomeiwen.com/i14497686/86545a1b766d23ca.png)
…
作业2
…
实现思路
- 定义数组存放用户输入的数据
- 使用冒泡排序算法
- 循环输出交换后的数组
…
代码
…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp40
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[6];
Console.WriteLine("请输入6个数字:");
for (int i = 0; i < a.Length; i++)
{
Console.Write("请输入第{0}个数字:", i + 1);
a[i] = Convert.ToInt32(Console.ReadLine());
}Console.Write("排序后:");
Array.Sort(a);
Array.Reverse(a);
for (int i = 0; i < a.Length; i++)
{
Console.Write("{0}\t", a[i]);
}
Console.ReadKey();
}
}
}
…
效果
…
…
网友评论