2道VB 题目 谢谢高手帮忙下

来源:百度知道 编辑:UC知道 时间:2024/06/06 10:30:02
编程实现,找出1~1000之间的孪生素数。孪生素数为素数之间的差为2的两个素数,例如:3,5;5,7…。 还求一题 键盘输入a,b,c的值,判断它们能否构成三角形的3个边。如果能构成三角形,则计算三角形的面积。 谢谢了

public sub prime;
dim k as integer;
dim a(1000) as integer;
k:=1;a[1]=3;
for i=2 to 1000
p=true;
for j=2 to (i-1) do if (i mod j=0) then p=false;
if p then
k=k+1;
a[k]=i;
if (a[k]-a[k-1]=2) then print i;
end;
next i
end sub;

public sub san;
dim a,b,c as integer;
input a,b,c;
if (a+b>c)and(a+c>b)and(b+c>a) then
p:=(a+b+c)/2;
print sqr(p*(p-a)*(p-b)*(p-c));
else
print 'No!'
endif
end sub;