…
作業(yè)1
…
步驟:
1.定義數(shù)組存儲(chǔ)價(jià)格,并利用循環(huán)輸入。
2.定義變量min保存當(dāng)前的最低價(jià)。
- 將min和數(shù)組中的其余元素依次比較。
…
代碼
…
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("請(qǐng)輸入4家店的價(jià)格:");
int i;
for (i = 0; i < money.Length; i++)
{
Console.Write("第{0}店的價(jià)格:", 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("最低價(jià)是:{0}", min);
Console.ReadKey();
}
}
}
…
效果
…

…
作業(yè)2
…
實(shí)現(xiàn)思路
- 定義數(shù)組存放用戶(hù)輸入的數(shù)據(jù)
- 使用冒泡排序算法
- 循環(huán)輸出交換后的數(shù)組
…
代碼
…
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("請(qǐng)輸入6個(gè)數(shù)字:");
for (int i = 0; i < a.Length; i++)
{
Console.Write("請(qǐng)輸入第{0}個(gè)數(shù)字:", 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();
}
}
}
…
效果
…
…