天高任鸟飞,海阔凭鱼跃
分类:
2010-06-19 19:37:07
数据汇总及排序程序代码
---------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int[] score = { 70, 65, 80, 45, 90, 92, 60 };
int temp;
for (int i = 0; i < score.Length; i++)
{
for (int n = 6; n > i; n--)
{
if (score[n] > score[n - 1])
continue;
temp = score[n - 1];
score[n - 1] = score[n];
score[n] = temp;
}
Label1.Text += Convert.ToString(score[i]) + "  ";
}
}
//以上程序是用于对一组数据进行排序所设计的!
protected void Button2_Click(object sender, EventArgs e)
{
int[] num = { 70, 65, 80, 45, 90, 92, 60 };
int min = num[0];
for (int a = 0; a < num.Length; a++)
{
if (num[a] > min)
continue;
min = num[a];
Label2.Text = Convert.ToString(min);
}
}
//以上程序是用于在一组数据进行提取最小值!
protected void Button3_Click(object sender, EventArgs e)
{
int[] num = { 70, 65, 80, 45, 90, 92, 60 };
int max = num[0];
for (int b = 0; b < num.Length; b++)
{
if (num[b] < max)
continue;
max = num[b];
Label3.Text = Convert.ToString(max);
}
}
//以上程序是用于在一组数据进行提取最大值!
protected void Button4_Click(object sender, EventArgs e)
{
int[] num = { 70, 65, 80, 45, 90, 92, 60 };
int sum=0;
for (int j = 0; j < num.Length; j++)
{
sum+=num[j];
Label4.Text = Convert.ToString(sum);
}
}
//以上程序是用于在一组数据进行求和汇总的!
protected void Button5_Click(object sender, EventArgs e)
{
int[] num = { 70, 65, 80, 45, 90, 92, 60 };
int sum = 0;
double ave;
for (int k = 0; k < num.Length; k++)
{
sum = sum + num[k];
ave = Convert.ToDouble(sum / (k + 1));
Label5.Text =Convert.ToString(ave);
}
}
//以上程序是用于在一组数据进行统计求平均值的!
}