"A arte de programar consiste na arte de organizar e dominar a complexidade."

quarta-feira, 2 de dezembro de 2015

Ficha nº14

1.

Código:

Private Sub Command1_Click()
    Dim mat(5, 5) As Integer, i As Integer, j As Integer, maior As Integer, linha As Integer, coluna As Integer
    Picture1.Cls
    linha = 0
    coluna = 0
    maior = 0
    
    Randomize
    For i = 0 To 5
        For j = 0 To 5
            mat(i, j) = Int(Rnd() * 50) + 1
            If mat(i, j) > maior Then
                maior = mat(i, j)
                linha = i
                coluna = j
            End If
            Picture1.Print mat(i, j);
        Next j
        Picture1.Print Chr(13)
    Next i
    
    MsgBox "O maior número da matriz é " & maior & ". Está na linha " & linha & " e na coluna " & coluna & ".", vbInformation, "saida"
End Sub

2.

Código:

Private Sub Command1_Click()
    Dim mat(2, 4) As Integer, i As Integer, j As Integer, pares As Integer, zeros As Integer, impares As Integer
    
    pares = 0
    zeros = 0
    impares = 0
    
    Randomize
    For i = 0 To 2
        For j = 0 To 4
            mat(i, j) = Int(Rnd() * 26)
            If mat(i, j) = 0 Then
                zeros = zeros + 1
            ElseIf mat(i, j) Mod 2 = 0 Then
                pares = pares + 1
            Else
                impares = impares + 1
            End If
            Picture1.Print mat(i, j);
        Next j
        Picture1.Print Chr(13)
    Next i
    
    MsgBox "Há na matriz " & pares & " números pares, " & impares & " números impares e " & zeros & " zeros.", vbInformation, "Saida"
End Sub

3.

Código:

Private Sub Command1_Click()
    Dim notas(1 To 5, 1 To 3) As Integer, i As Integer, j As Integer, negativa As Integer, positiva As Integer, sup16 As Integer
    Picture1.Cls
    negativa = 0
    positiva = 0
    sup16 = 0
    
    For i = 1 To 5
        For j = 1 To 3
            Do
                notas(i, j) = Val(InputBox("Introdozua a nota do " & i & " aluno no " & j & " prova:", "Entrada de dados"))
                If notas(i, j) < 0 Or notas(i, j) > 20 Then
                    MsgBox "A nota introduzida é inválida", vbCritical, "Aviso"
                End If
            Loop While notas(i, j) < 0 Or notas(i, j) > 20
        Next j
    Next i
    
    For i = 1 To 5
            If notas(i, 1) < 10 Then
                negativa = negativa + 1
            End If
            If notas(i, 2) > 10 Then
                positiva = positiva + 1
            End If
            If notas(i, 3) > 16 Then
                sup16 = sup16 + 1
            End If
    Next i
    
    For i = 1 To 5
        For j = 1 To 3
            Picture1.Print notas(i, j);
        Next j
        Picture1.Print Chr(13)
    Next i
    
    MsgBox "Na 1 prova houve " & negativa & " negativas, na 2 prova houve " & positiva & " positivas e na 3 prova houve " & sup16 & " notas superiores a 16.", vbInformation, "Saida"
        
End Sub

4.

Código:

Private Sub Command1_Click()
    Dim mat(3, 3) As Integer, maior(3) As Integer, menor(3) As Integer, i As Integer, j As Integer
    
    Picture1.Cls
    
    Randomize
    For i = 0 To 3
        For j = 0 To 3
            mat(i, j) = Int(Rnd() * 10)
        Next j
    Next i
    
    For i = 0 To 3
        menor(i) = 10
    Next i
    
    For i = 0 To 3
        For j = 0 To 3
            Picture1.Print mat(i, j);
            If mat(i, j) > maior(i) Then
                maior(i) = mat(i, j)
            End If
        Next j
        Picture1.Print Chr(13)
    Next i
        
    
    For j = 0 To 3
        For i = 0 To 3
            If mat(i, j) < menor(j) Then
                menor(j) = mat(i, j)
            End If
        Next i
    Next j
    
    For i = 0 To 3
        Picture2.Print maior(i);
        Picture3.Print menor(i);
    Next i
    
    
End Sub

Private Sub Command2_Click()
End
End Sub

5.

Código:

Private Sub Command1_Click()
    Dim vendas(1 To 3, 1 To 4) As Integer, i As Integer, j As Integer, total_vend As Integer, total_tri As Integer, total_ano As Integer

    Picture1.Cls
    Picture2.Cls
    Picture3.Cls

    total_vend = 0
    total_tri = 0
    total_ano = 0
    

    For i = 1 To 3
        For j = 1 To 4
            Do
                vendas(i, j) = Val(InputBox("Introduza o total de vendas do " & i & " vendedor no " & j & " trimestre:", "Entrada de dados"))
                If vendas(i, j) < 0 Then
                    MsgBox "O valor introduzido é inválido", vbCritical, "Aviso"
                End If
            Loop While vendas(i, j) < 0
        Next j
    Next i
    
    For i = 1 To 3
        For j = 1 To 4
            total_vend = total_vend + vendas(i, j)
        Next j
        Picture1.Print i & " vendedor: " & total_vend
        Picture1.Print Chr(13)
        total_vend = 0
    Next i
    
    For j = 1 To 4
        For i = 1 To 3
            total_tri = total_tri + vendas(i, j)
        Next i
        Picture2.Print j & " trimestre: " & total_tri
        Picture2.Print Chr(13)
        total_tri = 0
    Next j
    
    For i = 1 To 3
        For j = 1 To 4
            total_ano = total_ano + vendas(i, j)
        Next j
    Next i
    
    For i = 1 To 3
        For j = 1 To 4
            Picture3.Print vendas(i, j);
        Next j
        Picture3.Print Chr(13)
    Next i
    
    MsgBox "Foram feitas no total " & total_ano & " vendas no ano inteiro.", vbInformation, "Saida"
End Sub

Sem comentários:

Enviar um comentário