匿名使用者
匿名使用者 發問時間: 電腦與網際網路程式設計 · 1 0 年前

怎麼用vb寫出這些題目,請大大幫忙 "

要怎麼用vb寫出這些??

學校出的問題不過沒給正確答案

剛學不太會弄.. 請大大幫忙囉

輸入一個數字求出其階乘

例如輸入8則算出8!=1*2*3*4*5*6*7*8=?

輸a,b,c 算出aX2+bX+c=0的二根

輸入一個數字N就印出N個*

例如輸入6就印出******

輸入一個數字N就印出下圖

*

**

***

****

.

.

.

***********(n個)

1 個解答

評分
  • 1 0 年前
    最佳解答

    =====================================

    階乘(Factorial),適用於 Visual Basic 6

    =====================================

    Option Explicit

    Private Const mstrZero As String = "0"

    Private Const mstrOne As String = "1"

    Private Const mstrTwo As String = "2"

    Private Const mstrThree As String = "3"

    Private Const mstrFour As String = "4"

    Private Const mstrFive As String = "5"

    Private Const mstrDot As String = "."

    Private Const mstrNeg As String = "-"

    Private Const basechr As String = "B"

    Private Const basesep As String = ","

    Private Const mintAsc0 As Integer = 48

    Private Const negative As Integer = -1

    Private Const positive As Integer = 1

    Private Const mintMaxLongDigit As Integer = 8

    Private Sub Command1_Click()

    Dim strX As String

    strX = dhFactorial(Text1.Text)

    txtResult.Text = strX

    End Sub

    ' 目 的: 階乘(Factorial)。

    Public Function dhFactorial(ByVal strX As String) As String ', strOutput As String)

    Dim lngIndex As Long

    Dim lngLast As Long

    Dim lngNumber As Long

    Dim lngProduct As Long

    Dim strMultiply As String

    Dim strOutput As String

    Dim strSwitch As String

    Dim strTemp As String

    If Len(strX) <= mintMaxLongDigit Then GoSub bfLong

    dhFactorial = strOutput

    Exit Function

    bfLong:

    strOutput = mstrOne

    For lngNumber = 2 To CLng(Val(strX))

    strMultiply = strOutput

    lngLast = Len(strMultiply)

    strOutput = Space(lngLast)

    lngProduct = 0

    For lngIndex = lngLast To 1 Step -1

    lngProduct = lngProduct + Val(Mid(strMultiply, lngIndex, 1)) * lngNumber

    Mid(strOutput, lngIndex, 1) = Chr(mintAsc0 + CInt(lngProduct Mod 10))

    lngProduct = lngProduct \ 10

    Next lngIndex

    If lngProduct Then

    strOutput = LTrim(Str(lngProduct)) & strOutput

    End If

    Next lngNumber

    Return

    End Function

還有問題?馬上發問,尋求解答。