下载此文档

VB计算机等级考试常用算法.doc


文档分类:IT计算机 | 页数:约8页 举报非法文档有奖
1/8
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/8 下载此文档
文档列表 文档介绍
交换(有两种方法)
例如交换a和b的值
c=a
a=b
b=c
a=a+b
b=a-b
a=a-b
求和
①1+2+3+…+n(偶数和、奇数和)
n=val()或n=inputbox(“输入n”)
for i=1 to n
sum=sum+i
next i
print sum 或 =sum
②1/1+1/2+1/3+…1/n
n=val()或n=inputbox(“输入n”)
for i=1 to n
sum=sum+1/i
next i
print sum 或 =sum
③1/2+2/3+3/4+4/5+…+(n-1)/n
For i=2 to n
sum=sum+(i-1)/i
Next i
④1/2+2/3+3/5+5/8+…的前10项的和
a=1
b=2
for i=1 to 10
sum=sum+a/b
c=a+b
a=b
b=c
next i
print sum
⑤a 到b的和,
if a>b then
c=a
a=b
b=c
end if
for i=a to b
sum=sum+i
next i
print sum
⑥1+(1+2)+(1+2+3)+…+(1+2+3+…+n)
for i=1 to n
s=0
for j=1 to i
s=s+j
next j
sum=sum+s
next i
print sum
⑦1到1000间能被3整除又能被7整除的数之和以及个数
sum%=0:c%=0
For i=1 to 1000
if I mod 3=0 and I mod 7=0 then
sum=sum+i
c=c+1
end if
Next i
Print sum,c
⑧求数列 s=1-1/3+1/5-1/7+1/9…1/(2n-1)的和
sum=0:sign=1
for i=1 to n
sum=sum+sign/(2*i-1)
sign=-sign
next i
print sum
素数问题
①判断一个数是否是素数;
flag=true
n=val()
for i=2 to n-1
if n mod i=0 then
flag=false
exit for
Next i
if flag=true then
print n;”是素数”
end if
②1000以内的素数之和; sum=0:c=0
for i=3 to n
flag=true
for j=2 to i-1
if i mod j=0 then
flag=false
exit for
end if
next j
if flag=true then
sum=sum+i
c=c+1
end if
Next i
print sum;c
(1000到2000素数之和)?
③小于1000的5个最大素数
for i=1000 to 3

VB计算机等级考试常用算法 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数8
  • 收藏数0 收藏
  • 顶次数0
  • 上传人ipod0b
  • 文件大小102 KB
  • 时间2017-07-24