VB编程 计算1!+2!+…5!

VB编程 计算1!+2!+…5!VB编程 VB编程 要代码 要代码

第一种(对比计算PrivateSubCommand1_Click()Timer1.Enabled=TrueTimer1.Interval=1'计算一次用时量EndSubPrivateSubForm_Load()Text2.Text="0"'计算方法初始化Text3.Text="0"'计算开始初始化Text4.Text="1"'次数计算初始化EndSubPrivateSubTimer1_Timer()DimaAsInteger,bAsStringIfVal(Text4.Text)<=Val(Text1.Text)Theni=Val(Text4.Text)b=Text2.TextIfb=0ThenText2.Text="1"Text3.Text=Text3.Text+iElseIfb=1ThenText2.Text="0"Text3.Text=Text3.Text-iEndIfText4.Text=Val(Text4.Text)+1ElseTimer1.Enabled=FalseEndIfEndSub第二种(规律计算)'耗时最少PrivateSubCommand1_Click()DimaAsIntegera=Val(Text1.Text)IfaMod2=0ThenText2.Text=-1*a/2ElseText2.Text=-1*(a-1)/2+aEndIfEndSub
温馨提示:内容为网友见解,仅供参考
第1个回答  2020-01-02
第一种(对比计算PrivateSubCommand1_Click()Timer1.Enabled=TrueTimer1.Interval=1'计算一次用时量EndSubPrivateSubForm_Load()Text2.Text="0"'计算方法初始化Text3.Text="0"'计算开始初始化Text4.Text="1"'次数计算初始化EndSubPrivateSubTimer1_Timer()DimaAsInteger,bAsStringIfVal(Text4.Text)<=Val(Text1.Text)Theni=Val(Text4.Text)b=Text2.TextIfb=0ThenText2.Text="1"Text3.Text=Text3.Text+iElseIfb=1ThenText2.Text="0"Text3.Text=Text3.Text-iEndIfText4.Text=Val(Text4.Text)+1ElseTimer1.Enabled=FalseEndIfEndSub第二种(规律计算)'耗时最少PrivateSubCommand1_Click()DimaAsIntegera=Val(Text1.Text)IfaMod2=0ThenText2.Text=-1*a/2ElseText2.Text=-1*(a-1)/2+aEndIfEndSub
第2个回答  推荐于2018-03-31
dim s as double
dim i as double
dim j as double
s=0
j=1
for i=1 to 5
j = j * i
s=s+j
next i
print s本回答被提问者和网友采纳

VB编程 计算1!+2!+…5!
第一种(对比计算PrivateSubCommand1_Click()Timer1.Enabled=TrueTimer1.Interval=1'计算一次用时量EndSubPrivateSubForm_Load()Text2.Text="0"'计算方法初始化Text3.Text="0"'计算开始初始化Text4.Text="1"'次数计算初始化EndSubPrivateSubTimer1_Timer()DimaAsInteger,bAsStringIfVal(Text4.Text)<...

VB程序:求S=1!+2!+3!+4!+5!+6!+7!+8!+……+99!的值是多少?
99的阶乘接近10的156次方,也就是说,是一个155位的数值,这个数值在VB的数值类型中,是无法精确存储的。一般算法类型的编程题目,会求这个值的后6位这样的问题,或者使用贪心算法计算阶乘和问题,这类问题通常不会超过10的阶乘值或者整数变量范围。s=0 for i= 1 to 99 for j=1 to i s1=1 s1...

调用计算n阶乘的函数,计算并输出1!+2!+3!+...+5!的值。
include<stdio.h>int fun(int n){ int s=1,i;for(i=1;i<=n;i++) s*=i;return s;}main(){ int i,s=0; for(i=1;i<=5;i++) s+=fun(i); printf("%d",s);}如图所示,望采纳。。。

VB中用sub过程编程1!+2!+3!...+10!的代码,一定要是Sub过程
Private Sub jc(x As Integer, y As Single)Dim i As Integer y = 1 For i = 1 To x y = y * i Next i End Sub Private Sub Form_Click()Dim j As Integer, s As Single, sum As Single For j = 1 To 10 Call jc(j, s)sum = sum + s Next j Print sum End Sub ...

编程计算1!+2!+3!+...+50!
include <stdio.h>double fac(int n){ double s=1; for(int i=1;i<=n;i++) s=s*i; return s; } int main(){ double sum=0; for(int i=1;i<=50;i++) sum=sum+fac(i); printf("1!+2!+...+50!=%lf\\n",sum); return 0; } ...

求VB程序代码 1!+2!……20!的和
For i = 1 To 20 Multiply MDigit, i If UBound(MDigit) > UBound(Sum) Then ReDim Preserve Sum(UBound(MDigit))End If Add Sum, MDigit Next Dim result As String For i = UBound(Sum) To 0 Step -1 result = result & Sum(i)Next MsgBox result End Sub 最后结果是:...

计算1!+2!+3!+...+n!=?用数学方法,C语言编程,vB编程都行.
include<stdio.h> void main() { int n,i,j,sum=0,a=1; printf("键入数n\\n"); if(n==0) {sum=1;} scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { a=a*j; } sum=sum+a; a=1; } printf("\\n%d\\n",sum); } ...

编写程序,计算1!+2!+3!+...+n!的值,其中n的值由用户输入。答案给出来了...
include <stdio.h> main ( ){int k,l,n;\/*n代表用户输入的值;k是一个循环变量,代表从1到n;l也是循环变量代表从1到k,用来计算 k!时用*\/ double sum=0,fact_k=1;\/*fact-k=1,这是给fact_k赋一个初始值,下面在计算每一个k的阶乘时会用到*\/ printf("Please Input n:");scanf...

VB输入N的值编程计算1!+2!+3!+...+n!
Dim i, m, n, result, t i = InputBox("请输入N的值","提示")result = 0 If IsNumeric(i) Then For m = 1 To n t = 1 For n = 1 To m t = t*n Next n result = result + t Next m MsgBox "结果为: " & result Else MsgBox "N不是数字!", "错误"End If ...

计算1!+2!+3!+4!+5!+6!+7!+8!+9+10!,用C语言编写程序
include <stdio.h> long GetFactoria(int n){ long ret=1,i=n;while(i!=0){ ret=ret*i;i--;} return ret;} void main(){ int i;long sum=0;for(i=1;i<11;i++){ sum+=GetFactoria(i);} printf("1!+2!+3!+4!+5!+6!+7!+8!+9!+10!=%ld\\n",sum);} 这个应该没...

相似回答