Taur33
Messages postés85Date d'inscriptionvendredi 24 septembre 2010StatutMembreDernière intervention20 mai 2011
-
14 janv. 2011 à 19:54
Taur33
Messages postés85Date d'inscriptionvendredi 24 septembre 2010StatutMembreDernière intervention20 mai 2011
-
15 janv. 2011 à 15:19
bonsoir à tous,
j'aurais besoin de convertir le code suivant en vb
je précise que j'ai déjà essayé des logiciels qui soit disant le faisait mais cela ne fonctionne pas :
#define TAILLE 2147
void fact(int n)
{
int tab[TAILLE];
int k=1;
int m,i,p;
int base=1000000;
int x,y;
//initialisation du tableau de stockage
for(i=0;i<TAILLE;i++) tab[i]=0;
tab[TAILLE-1]=1;
//Calcul des composantes du résultats et stockage ds le tableau
for(m=1;m<=n;m++)
{
p=0;
for(i=1;i<=k;i++)
{
x=(p+m*tab[TAILLE-i]);
y=x%base;
p=(x-y)/base;
tab[TAILLE-i]=y;
}
if(p!=0) tab[TAILLE+1-k]=p;
k++;
}
//affichage du résultat
k=0;
while(tab[k]==0) k++;
cout<<tab[k];
for(i=k+1;i<TAILLE;i++)
{
if (tab[i]<10) cout<<"00000"<<tab[i];
else if (tab[i]<100) cout<<"0000"<<tab[i];
else if (tab[i]<1000) cout<<"000"<<tab[i];
else if (tab[i]<10000) cout<<"00"<<tab[i];
else if (tab[i]<100000) cout<<"0"<<tab[i];
else cout<<tab[i];
}
cout<<endl;
}
Taur33
Messages postés85Date d'inscriptionvendredi 24 septembre 2010StatutMembreDernière intervention20 mai 2011 15 janv. 2011 à 15:19
Ok c'est résolu
je donnel'algo en vb si quelqu'un est intéressé par la convertion du C en VB et par le calcul d'une factorielle avec tous les chiffres:
Public Function facto(ByVal N As Integer) As String
Dim tab(N) As Integer
Dim k As Integer = 1
Dim base As Long = 1000000
Dim x As Long
Dim y As Long
Dim i As Long
Dim m As Long
Dim p As Long
Dim TAILLE As Long = N
'initialisation du tableau de stockage
tab(TAILLE - 1) = 1
' Calcul des composantes du résultats et stockage ds le tableau
For m = 1 To N
p = 0
For i = 1 To k
x = (p + m * tab(TAILLE - i))
y = x Mod base
p = (x - y) / base
tab(TAILLE - i) = y
Next
If p <> 0 Then
tab(TAILLE + 1 - k) = p
End If
k += 1
Next
'affichage du résultat
k = 0
While tab(k) = 0
k += 1
End While
facto = tab(k)
For i = k + 1 To TAILLE - 1
Select Case tab(i)
Case Is < 10
facto = facto & "00000" & tab(i)
Case Is < 100
facto = facto & "0000" & tab(i)
Case Is < 1000
facto = facto & "000" & tab(i)
Case Is < 10000
facto = facto & "00" & tab(i)
Case Is < 100000
facto = facto & "0" & tab(i)
Case Else
facto = facto & tab(i)
End Select
Next
End Function