试编写程序,求1+2!+3!+……+20!的值

来源:百度知道 编辑:UC知道 时间:2024/09/28 06:45:53
饿..
要用
DO

LOOP UNTIL
或者
WHILE

WEND
结构..

谢谢..

private sub form_click()
dim sum as single
dim item as single
dim i as integer,n as integer
sum=1
item=1
i=1
do while i<=20
item =item*i
sum = sum +item
i=i+1
loop
print " 1+2!+3!+……+20!=";sum
end sub

如果你有一个处理大整数、保证不溢出的类BigInteger,那么一切就简单了:
BigInteger func() {
BigInteger sum = 0;
BigInteger prod = 1;
int n = 1;
do {
prod *= n;
sum += prod;
++n;
} while(n <= 20)
return sum;
}