高分!急求VF的编成题答案 会的来哈

来源:百度知道 编辑:UC知道 时间:2024/09/13 07:45:19
任意输入一个数,计算从1到这个数的相加之和 详细过程!!用子程序编!

clear
accept "请输入一个整数:"to xh
xh=int(xh)
xy=1
sum=0
do while xy<=xh
sum=sum+xy
xy=xy+1
enddo
?? "计算结果为: "
"sum

set talk off
? "能被7整除的数: "
store 0 to s1,s2,s3,s4,s5,k

for i=1 to 100
s1=s1+i
s2=s2+i*i

if mod(i,2)=0
s4=s4+i
else
s3=s3+i
endif

if mod(i,7)=0
?? str(i,3)
endif
endf

for i=2 to 100
k=sqrt(i)

f=.t.
for j=2 to k
if mod(i,j)=0
f=.f.
exit
endif
endf

if f
s5=s5+i
endif
endf

? "从1到100的数的和:"+str(s1,5)
? "从1到100的整数平方和:"+str(s2,8)
? "从1到100的的奇数和:"+str(s3,5)
? "从1到100的的偶数和:"+str(s4,5)
? "从1到100的质数和:"+str(s5,5)
return

clear
i=1
input "请输入要求和的数字" to n
do while i<=n<