发布时间:2019-07-29 17:27:30
参考程序如下:
//获取奇数
int odd[100];//有100个奇数
int i, ind=0;
for(i=100; i<=300; i++)
{
if(i%2==1)
{
odd[ind++]=i;
}
}
//获取素数
int j, k, p=0;
for(j=0; j<100; j++)
{
int num=odd[j];
int check=1;//若是素数则为1
for(k=0; k<=num/2; k++)
{
if(num%k==0)
{
check=0;
break;
}
}
if(check==1)
{
printf("%6d", k);
if(++p%5==0) printf("\n");
}
}
//试试呢
function f(a) '判断是否为素数,是则返回本身,不是则返回0 f=0 for i=2 to a if not(a mod i) then exit function f=a end function function p(a()) '每行10个数输出数组a() for i=lbound(a) to ubound(a) step 10 for j=1 to 10 print a(i+j); next j print next i end function function s(a()) '求数组a()的和 for i=lbound(a) to ubound(a) s=s+i next i end function