定义一个长度为10的一维整型数组,填充不能重复的随机值。输出数组中最大值和最小值,并利用数组中所有的

定义一个长度为10的一维整型数组,填充不能重复的随机值。输出数组中最大值和最小值,并利用数组中所有的值输出一个第一行为一个数字并居中

第1个回答  2010-09-03
#include<iostream.h>
using namespace std;
void AssigValue(int n,int a[]){
int k;
for(;;){
k = (int)(rand() * 1000);
for(int j = 0; j < n; j++){
if(a[j] == k) break;
}
if(j == n) break;
}
a[n] = k;
}
int maxdata(int a[]){
int max = a[0];
for(int i = 1; i <= 10; i++){
if(a[i] > max)
max = a[i];
}
return max;
}
int mindata(int a[]){
int min = a[0];
for(int i = 1; i <= 10; i++){
if(a[i] < min)
min = a[i];
}
return min;
}

void main(){
int a[10];
for(int i = 0; i < 10; i++){
AssigValue(i,a);
}
cout<<"The array data are:\n";
for(int k = 0; k < 10; k++)
cout<<a[i]<<" ";
cout<<"\n";
cout<<"The max data is:"<<maxdata(a)<<"\n";
cout<<"The min data is:"<<mindata(a)<<"\n";
}

新写的代码,未编译执行,可能有地方有语法错误
第2个回答  2010-09-16
Public Class Form1
Dim a%
Dim m#
Dim n#
Dim d% = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text += "7"
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TextBox1.Text += "8"
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
TextBox1.Text += "9"
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
TextBox1.Text += "4"
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TextBox1.Text += "5"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text += "6"
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
TextBox1.Text += "1"
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Text += "2"
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
TextBox1.Text += "3"
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
TextBox1.Text += "0"
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
If TextBox1.Text "" Then If d = 0 Then TextBox1.Text += "."
d = 1
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
d = 0
a = 1
m = CDbl(TextBox1.Text)
TextBox1.Clear()
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
d = 0
a = 2
m = CDbl(TextBox1.Text)
TextBox1.Clear()
End Sub
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
d = 0
a = 3
m = CDbl(TextBox1.Text)
TextBox1.Clear()
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
d = 0
a = 4
m = CDbl(TextBox1.Text)
TextBox1.Clear()
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
TextBox1.Clear()
d = 0
End Sub
Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
n = CDbl(TextBox1.Text)
If a = 1 Then TextBox1.Text = Str(m + n)
If a = 2 Then If (m - n) 0 Then TextBox1.Text = Str(n - m) + "-" Else TextBox1.Text = Str(m - n)
If a = 3 Then TextBox1.Text = Str(m * n)
If a = 4 Then TextBox1.Text = Str(m / n)
End Sub
End Class
这是主要代码,功能不全,以前写的,现在不想写了。你可以参考下。本回答被提问者采纳
相似回答
大家正在搜