Esercizio 1 con Vb, Semplice esempio per newbie

« Older   Newer »
  Share  
Ikezawa
icon5  CAT_IMG Posted on 21/12/2010, 02:19     +1   -1




Da wikipedia

l'aritmetica modulare si basa sul concetto di congruenza modulo n . Dati tre numeri interi a, b, n, con n ≠ 0, diciamo che a e b sono congruenti modulo n se la loro differenza (a − b) è un multiplo di n. In questo caso scriviamo

a = b mod(n)

e diciamo che a è congruo a b modulo n. Per esempio, possiamo scrivere

38 = 14 mod(n)

poiché 38 − 14 = 24, che è un multiplo di 12.

Genera le prime 100 congruenze con n=4. testato dovrebbe essere giusto
CODICE
Public Class Form1
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Genera.Click
       Dim a As Integer
       Dim b As Integer
       Dim n As Integer
       Dim tmp As Integer

       n = 4

       For b = 0 To 100
           For a = 0 To 100
               If a > b Then
                   tmp = a - b
                   tmp = tmp Mod n
                   If tmp = 0 Then
                       txt.Text = txt.Text + "(" & a & "-" & b & ")" & "MOD(" & n & ") " & Chr(13)
                   End If
               End If
           Next a
       Next b
   End Sub
End Class
 
Top
0 replies since 21/12/2010, 02:19   128 views
  Share