随机产生10个1~100的正整数放入数组,显示产生的数,求这组数的最大值,最小值和

如题所述

第1个回答  2011-06-18
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 10
void main()
{
int a,i,max=0,min=100,num=0;
srand(time(NULL));
for(i=0;i<N;i++)
{
a=rand()%100+1;
num+=a;
if(a>max) max=a;
if(a<min) min=a;
}
num/=N;
printf("最大值是:%d,最小值是:%d,平均值是:%d\n",max,min,num);
}

我的就是C
第2个回答  2011-06-15
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;

namespace StudyRandom
{
class Program
{
public static int GetRandom()
{
Thread.Sleep(25);
Random r = new Random();
return r.Next(1, 100);

}
static void Main(string[] args)
{
int[] myArray = new int[10];
int max =myArray[0];
int min = myArray[0];
int count = 0;
int countM=0;
for(int i=0;i<10;i++)
{
myArray[i] = GetRandom();
Console.WriteLine(myArray[i]);
if (myArray[i] > max)
{
max = myArray[i];
}
if (myArray[i] < min)
{
min = myArray[i];
}
count = max + min;
countM += myArray[i];
}
Console.WriteLine("最大值max=" + max);
Console.WriteLine("最小值min=" + min);
Console.WriteLine("最大值和最小值的和" + count);
Console.WriteLine("平均值" + countM / 10);
Console.ReadLine();
}
}
}
这是C#版本的

参考资料:http://www.xnnye.com

本回答被提问者采纳
第3个回答  2011-06-15
Private Sub Command1_Click()
Dim a(9)
Sum = 0
Randomize
For i = 0 To 9
a(i) = Int(Rnd * 100) + 1
Print a(i);
Sum = Sum + a(i)
Next i
Min = a(0)
Max = a(0)
For i = 1 To 9
If a(i) < Min Then
Min = a(i)
End If
If a(i) > Max Then
Max = a(i)
End If
Next i
Print
Print "最大值" & Max
Print "最小值" & Min
Print "和" & Sum
End Sub追问

平均值呢

追答

Private Sub Command1_Click()
Dim a(9)
Sum = 0
Randomize
For i = 0 To 9
a(i) = Int(Rnd * 100) + 1
Print a(i);
Sum = Sum + a(i)
Next i
Min = a(0)
Max = a(0)
For i = 1 To 9
If a(i) Max Then
Max = a(i)
End If
Next i
Print
Print "最大值" & Max
Print "最小值" & Min
Print "和" & Sum
print "平均值" & sum/10
End Sub

相似回答