新人求解答
现在一个5行5列的随机数组 找出每一行最大的一个数看这个数是不是这一列最大的 如果是就提出 求解
#include <stdio.h> int main() { int a[5][5], b[5]={0,0,0,0,0}; //a[5][5]值自己初始化 int c=0; int i, j; for(i=0; i<5; i++) { for(j=0; j<5; j++) { if(a[i][j] >= b[c]) { b[c] = a[i][j]; } } c++; } }
Option Explicit Dim a(4, 4) As Single Private Sub Command1_Click() Dim i As Integer, j As Integer Text1.Text = "" For i = 0 To 4 For j = 0 To 4 a(i, j) = Round(Rnd, 3) Text1.Text = Text1.Text & a(i, j) & " " Next Text1.Text = Text1.Text & vbCrLf Next Text1.Text = Text1.Text & vbCrLf judge End Sub Private Sub Form_Load() Me.Show End Sub Sub judge() Dim i As Integer, j As Integer, k As Integer Dim rowmax As Single Dim rowmaxp Dim s As Boolean 'Is the maxmium number of a column ture:yes false:no For i = 0 To 4 rowmax = 0 For j = 0 To 4 If a(i, j) > rowmax Then rowmax = a(i, j) rowmaxp = j End If Next s = True For k = 0 To 4 If rowmax < a(k, rowmaxp) Then s = False: Exit For Next If s = True Then Text1.Text = Text1.Text & rowmax & " in the " & i & " Row" & " is the maxmium number of the " & rowmaxp & " column" & vbCrLf Next End Sub