
有两种办法:
第一种就是用随机数进行模拟,然后进行至少100轮的模拟,取平均数
第二种就是用公式,根据概率学进行公式推导,然后使用C语言进行计算。
第一种并不能很准确,但是有说服力,模拟轮数越多越趋向于准确
第二种准确并有说服力,但是需要理论支持去计算。
公式的话:
全部可能出现的排列,是2的1000次方
特定位置可能出现满足的排列,比如前10个都是正面,剩下的随便排列,就是2的990次方
特定位置数,一共是991个
所以,几率就是:991 2^990 / 2^1000
(好久没有算过了,可能不太对,但是思路差不多,你好好想想吧)
因为,前11个都是正面的,同时满足第一个和第二个位置的,是重复,需要排除一个,所以还需要额外考虑排除,需要进行处理一下……实际比上述的几率小,具体公式仍需推导……非专业人员帮不到你
假设是A1,A2,A3三个单元格,内容为"正","反"
A4单元格写入公式
=VLOOKUP(A1&A2&A3,{"正正正",1;"反反反",2;"正反正",3;"反正反",4;"正正反",5;"反反正",6;"正反反",7;"反正正",8},2,)
这样试一下,如果编号不对自已改一下
如果要求A1至A3有任一单元格为空单元格,则不显示,那公式改成
=IF(OR(A1="",A2="",A3=""),"",VLOOKUP(A1&A2&A3,{"正正正",1;"反反反",2;"正反正",3;"反正反",4;"正正反",5;"反反正",6;"正反反",7;"反正正",8},2,))
Private Function setdata(num As Integer) As String '数字转换
Select Case num
Case 0
setdata = "零"
Case 1
setdata = "壹"
Case 2
setdata = "贰"
Case 3
setdata = "叁"
Case 4
setdata = "肆"
Case 5
setdata = "伍"
Case 6
setdata = "陆"
Case 7
setdata = "柒"
Case 8
setdata = "捌"
Case 9
setdata = "玖"
End Select
End Function
Private Function chang(aaa As Integer) As String '位数转换
Select Case aaa
Case 1
chang = ""
Case 2
chang = "十"
Case 3
chang = "百"
Case 4
chang = "千"
Case 5
chang = "万"
Case 6
chang = "十"
Case 7
chang = "百"
Case 8
chang = "千"
Case 9
chang = "亿"
Case 10
chang = "十"
End Select
End Function
Private Sub Form_Activate() '设定文本长度
Text2MaxLength = 10
Text2SetFocus
End Sub
Private Sub Text2_Change() '小写转大写
Dim i As Integer
Dim j As Integer
Dim myint As Integer
Dim myint1 As Integer
Dim mydoub As Double
Dim mystr As String
Dim mystr1 As String
Dim mystr2 As String
Dim mystr3 As String
Dim mystr4 As String
Dim money As Long
Dim money1 As Integer
Dim money2 As Long
mystr = Text2Text
myint = InStr(mystr, "")
If myint = 0 Then
mystr = Text2Text
Else
mystr3 = Right(Text2Text, Len(Text2Text) - myint)
If mystr3 <> "" Then '转换小数位
mystr4 = Left(mystr3, 1)
mystr3 = Right(mystr3, Len(mystr3) - 1)
If mystr4 <> "0" Then
mystr2 = mystr2 + setdata(Val(mystr4)) + "角"
End If
If mystr3 <> "" Then
mystr4 = Left(mystr3, 1)
mystr2 = mystr2 + setdata(Val(mystr4)) + "分"
End If
End If
mystr = Left(Text2Text, myint - 1)
End If
j = Len(mystr)
For i = 1 To Len(mystr) '转换整数位
money2 = Left(mystr, i)
money1 = Right(money2, 1)
If money1 = 0 Then
If j = 5 Then
If Right(mystr1, 1) <> "万" Then mystr1 = mystr1 & "万"
Else
If Right(mystr1, 1) <> "零" And Right(money, j) > 0 Then mystr1 = mystr1 & "零"
End If
Else
mystr1 = mystr1 & setdata(money1) + chang(j)
End If
j = j - 1
Next i
Text1Text = mystr1 & "元" & mystr2 '显示大写
End Sub
Private Sub Command1_Click()
End
End Sub
Private Sub 清屏按钮_Click(sender As Object, e As EventArgs) Handles 清屏按钮Click
For Each 控件 As Control In MeControls
If 控件GetType = 美元框GetType Then
控件Text = ""
End If
Next
End Sub
Private Sub 人民币2美元_Click(sender As Object, e As EventArgs) Handles 人民币2美元Click
If 人民币框Text <> "" And 汇率框Text <> "" Then
Dim 人民币 As Decimal = CDec(人民币框Text)
Dim 汇率 As Decimal = CDec(汇率框Text)
美元框Text = (人民币 汇率)ToString("###")
End If
End Sub
Private Sub 美元2人民币_Click(sender As Object, e As EventArgs) Handles 美元2人民币Click
If 美元框Text <> "" And 汇率框Text <> "" Then
Dim 美元 As Decimal = CDec(美元框Text)
Dim 汇率 As Decimal = CDec(汇率框Text)
人民币框Text = (美元 汇率)ToString("###")
End If
End Sub
Private Sub 结束按钮_Click(sender As Object, e As EventArgs) Handles 结束按钮Click
End
End Sub
Private Sub 主窗体_Load(sender As Object, e As EventArgs) Handles MyBaseLoad
VBPText = "VISUAL BASIC PROGRAMMING"
老师Text = "i am a teacher"
人民币兑换Show()
End Sub
Private Sub 转换按钮_Click(sender As Object, e As EventArgs) Handles 转换按钮Click
If VBPText <> "" Then
VBPText = StrConv(VBPText, VbStrConvLowercase)
老师Text = StrConv(老师Text, VbStrConvUppercase)
End If
End Sub
Private Sub 统计按钮_Click(sender As Object, e As EventArgs) Handles 统计按钮Click
字符统计框Text = CStr(VBPTextLength)
End Sub
Private Sub 取字符串按钮_Click(sender As Object, e As EventArgs) Handles 取字符串按钮Click
前六个字符Text = VBPTextSubstring(0, 6)
End Sub
以上就是关于用C语言编写一个程序,求掷硬币1000次,至少有一次连续出现10次正面的概率。或者讲讲算法。全部的内容,包括:用C语言编写一个程序,求掷硬币1000次,至少有一次连续出现10次正面的概率。或者讲讲算法。、excel中 有三个格子分别代表三个硬币 如何在第四个格子显示掷硬币的结果、用vb编制一个将人民币金额(不超过4位整数)转化为大写金额的程序。(1)单击转换(command1)text1是等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)