Accueil > > > ADDITION DE TRÈS GRANDS NOMBRES (PLUSIEURS MILLIERS DE CHIFFRES)
ADDITION DE TRÈS GRANDS NOMBRES (PLUSIEURS MILLIERS DE CHIFFRES)
Information sur la source
Description
Ce code ne travaille pas sur les types long, integer, double... mais sur les strings. La fonction "plus" a donc été recréée. On peut ainsi ajouter des nombres de plusieurs milliers de chiffres alors que visual basic dirait qu'il y a dépassement de capacité.
Source
- Public Function PLUS(a As String, b As String) As String
- Dim s_result As String
- Dim s_max As String, s_min As String
-
- If Len(a) > Len(b) Then
- s_max = a
- ElseIf Len(a) < Len(b) Then
- s_max = b
- Else
- If CInt(Left$(a, 1)) > CInt(Left$(b, 1)) Then
- s_max = a
- Else
- s_max = b
- End If
- End If
- If s_max = a Then s_min = b Else s_min = a
-
- Dim x As Double
- Dim x_max As Double
- Dim x_min As Double
-
- Dim c_min As Integer
- Dim c_max As Integer
- Dim c_result As Integer
- Dim retenue As Integer
-
- x = 0
- retenue = 0
-
- debutalgo:
- x_max = Len(s_max) - x
- c_max = CInt(Mid$(s_max, x_max, 1))
-
- If Len(s_min) > x Then
- x_min = Len(s_min) - x
- c_min = CInt(Mid$(s_min, x_min, 1))
- Else
- c_min = 0
- End If
-
- c_result = c_min + c_max + retenue
- If c_result > 9 Then retenue = 1: c_result = CStr(c_result - 10) Else retenue = 0
-
- s_result = c_result & s_result
-
- x = x + 1
- If x < Len(s_max) Then GoTo debutalgo
-
- PLUS = IIf(retenue <> 0, retenue, "") & s_result
- End Function
Public Function PLUS(a As String, b As String) As String
Dim s_result As String
Dim s_max As String, s_min As String
If Len(a) > Len(b) Then
s_max = a
ElseIf Len(a) < Len(b) Then
s_max = b
Else
If CInt(Left$(a, 1)) > CInt(Left$(b, 1)) Then
s_max = a
Else
s_max = b
End If
End If
If s_max = a Then s_min = b Else s_min = a
Dim x As Double
Dim x_max As Double
Dim x_min As Double
Dim c_min As Integer
Dim c_max As Integer
Dim c_result As Integer
Dim retenue As Integer
x = 0
retenue = 0
debutalgo:
x_max = Len(s_max) - x
c_max = CInt(Mid$(s_max, x_max, 1))
If Len(s_min) > x Then
x_min = Len(s_min) - x
c_min = CInt(Mid$(s_min, x_min, 1))
Else
c_min = 0
End If
c_result = c_min + c_max + retenue
If c_result > 9 Then retenue = 1: c_result = CStr(c_result - 10) Else retenue = 0
s_result = c_result & s_result
x = x + 1
If x < Len(s_max) Then GoTo debutalgo
PLUS = IIf(retenue <> 0, retenue, "") & s_result
End Function
Historique
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
ASYNC/AWAIT: COMPRENDRE COMMENT CA MARCHEASYNC/AWAIT: COMPRENDRE COMMENT CA MARCHE par fathi
Tout le monde est unanime pour dire que la programmation multi-thread et asynchrone est en train de devenir un sujet incontournable. Beaucoup de choses sont arrivées avec le framework 4 pour le code parallèle (TPL, PLinq,.) et bientôt, on va avoir l...
Cliquez pour lire la suite de l'article par fathi PAS D'INTELLITRACE SUR MON SITE WEB DANS IIS !PAS D'INTELLITRACE SUR MON SITE WEB DANS IIS ! par Etienne Margraff
J'ai récemment eu un problème pour obtenir l'intelliTrace sur un site web dans IIS. Il n'y avait pas de message d'erreur, rien dans le journal d'évènement Windows, et après 3 appels à une voyante, 2 visites chez un marabou, j'ai failli me résign...
Cliquez pour lire la suite de l'article par Etienne Margraff OFFICE 365 - SHAREPOINT ONLINE, QUELQUES LIMITATIONSOFFICE 365 - SHAREPOINT ONLINE, QUELQUES LIMITATIONS par junarnoalg
De nombreuses entreprises font le choix de SharePoint Online, service fourni au travers de l'offre de Microsoft Office 365. S'il est vrai que ce choix apporte un grand nombre d'avantages; rapidité de mise en œuvre, disponibilité, large couvertu...
Cliquez pour lire la suite de l'article par junarnoalg PRéSENTATION DES API REST DE WINDOWS AZURE : LISTER LES COMPTES DE STORAGEPRéSENTATION DES API REST DE WINDOWS AZURE : LISTER LES COMPTES DE STORAGE par richardc
http://www.c2idotnet.com/articles/presentation-des-api-rest-de-windows-azure-lister-les-comptes-de-storage
Désolé pour "toto", mais c2i existait avant blogs.developpeur.org et c'est mon site "officiel" ;-) ...
Cliquez pour lire la suite de l'article par richardc
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|