Archived
1
0
This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SomeLab/cs4/CS4_3/Program.cs
2025-11-01 08:20:49 +08:00

41 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
namespace CS4_3
{
public class Program
{
static void Main(string[] args)
{
int[] A = new int[10];
Random rand = new Random();
for (int i = 0; i < A.Length; i++)
{
A[i] = rand.Next(1, 999);
}
Console.WriteLine("原数组:");
for (int i = 0; i < A.Length; i++)
{
Console.Write(A[i] + " ");
}
// 冒泡排序
int temp;
for (int i = 0; i < A.Length - 1; i++)
{
for (int j = 0; j < A.Length - 1 - i; j++)
{
if (A[j] > A[j + 1])
{
temp = A[j];
A[j] = A[j + 1];
A[j + 1] = temp;
}
}
}
Console.WriteLine("\n排序后数组");
for (int i = 0; i < A.Length; i++)
{
Console.Write(A[i] + " ");
}
}
}
}