Oppure

Loading
22/04/11 13:09
RN
Dovrei scrivere un programma che determini la potenza intera di un numero utilizzando solo il prodotto. L'esponente e la base devono essere immessi dall'utente e bisogna utilizzare la struttura "do loop while". Potreste gentilmente aiutarmi poichè ho le idee un po' confuse? Grazie in anticipo!! :)
aaa
22/04/11 16:42
Sal47
Ciao, se ho ben compreso la tua richiesta, il problema potrebbe essere risolto come indicato nel listato seguente, anche se la soluzione forse non è molto elegante (sono anche io alle prime esperienze di VB6):
___________
Option Explicit
Dim base, check, esp, n, temp

Private Sub Command1_Click()
check = True
base = Val(txtBase): esp = Val(txtEsp)
n = 1
temp = 1
Do
Do While n <= (esp + 1)
n = n + 1
temp = temp * base
If n = esp + 1 Then
check = False
Exit Do
End If
Loop
Loop Until check = False
txtRisultato = temp
End Sub

Private Sub Form_Load()
base = Val(txtBase): esp = Val(txtEsp)
Label4 = base & " ^ " & esp & " = "
End Sub

Private Sub txtBase_Change()
Correggi
txtRisultato = ""
End Sub

Private Sub txtEsp_Change()
Correggi
txtRisultato = ""
End Sub

Public Sub Correggi()
Label4 = Val(txtBase) & " ^ " & Val(txtEsp) & " = "
End Sub
____________
Saluti.
Sal47
aaa