Section courante

A propos

Section administrative du site

SQR

Racine carré
Visual Basic

Syntaxe

Function SQR(n As Double) As Double

Paramètres

Nom Description
n Ce paramètre permet d'indiquer l'expression contenant le nombre à traiter

Description

Cette fonction retourne la racine carré.

Algorithme

MODULE SQR(X)
   SI X = 0.0 ALORS
      RETOURNE 0.0
   SINON
      M ← 1.0
      XNX
      BOUCLE FAIRE TANT QUE XN >= 2.0
         XN ← 0.25 x XN
         M ← 2.0 x M
      FIN BOUCLE FAIRE TANT QUE
      BOUCLE FAIRE TANT QUE XN < 0.5
         XN ← 4.0 x XN
         M ← 0.5 x M
      FIN BOUCLE FAIRE TANT QUE
      AXN
      B ← 1.0 - XN
      BOUCLE REPETER
         AA x (1.0 + 0.5 x B)
         B ← 0.25 x (3.0 + B) x B x B
      FIN BOUCLE JUSQU'A B ← 1.0E - 15
      RETOURNE A x M
   FIN SI

Remarque

Exemple

Voici un exemple permet d'afficher les racines carrés inférieurs à 1000 :

  1. Sub Main()
  2.  Dim R As Double
  3.  Dim S As String
  4.  R = 2
  5.  DO WHILE R <= 1000
  6.   S = S & "Sqrt(" & R & ")=" & SQR(R) & vbCrLf
  7.   R = R * R
  8.  LOOP 
  9.  MsgBox S
  10. End Sub

on obtiendra le résultat suivant :

Sqrt(2)=1.4142135623730951
Sqrt(4)=2
Sqrt(16)=4
Sqrt(256)=16


Dernière mise à jour : Lundi, le 19 novembre 2012