1.VB中怎么编程3阶魔方阵?
2.VB:如何编程:魔方方阵,魔方魔方码
3.vb魔方矩阵代码
4.vb魔方矩阵(n为奇数)
VB中怎么编程3阶魔方阵?
Private Sub Command1_Click()Dim a(,源码源代 ) As Integer, n As Integer
n = InputBox("请输入一个奇数 N=")
Print "N="; n
i = 1
j = n \ 2 + 1
k = 1
For i1 = 1 To n
For i2 = 1 To n
a(i, j) = k
k = k + 1
If i2 < n Then
i = i - 1
j = j + 1
If i = 0 Then i = n
If j > n Then j = 1
Else
i = i + 1
End If
Next i2
Next i1
For i = 1 To n
For j = 1 To n
Print Tab(4 * j); a(i, j);
Next j
Next i
End Sub
VB:如何编程:魔方方阵,
Private Sub Command1_Click()
Dim n As Integer
Dim r() As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim s As String
Me.Cls
n = InputBox("输入N")
If n Mod 2 <> 1 The魔方魔方码java请假源码n
MsgBox "N必须是奇数", vbCritical
Exit Sub
End If
ReDim r(1 To n * n) As Integer
k = 1
i = 1
j = n \ 2 + 1
While k <= n * n
r((i - 1) * n + j) = k
i = i - 1
j = j + 1
If i < 1 Then i = n
If j > n Then j = 1
If r((i - 1) * n + j) <> 0 Then
i = i + 2
j = j - 1
If i > n Then i = i - n
If j < 1 Then j = j + n
End If
k = k + 1
Wend
s = String(Len(Trim(Str(n * n))), "0")
For i = 1 To n
For j = 1 To n
Print Format(r((i - 1) * n + j), s); " ";
Next j
Next i
End Sub
Private Sub Form_Load()
Me.FontName = "宋体"
End Sub
vb魔方矩阵代码
3*3
dim a as intger
text2.text = 1
a=1
for a<9
a+1
text9.text = 2
text1.text = 3
text7.text = 4
text5.text = 5
.....
vb魔方矩阵(n为奇数)
我自己写了个C++的,里面用到了一些C++特有的源码源代功能,不能移到VB上,魔方魔方码心源码意但我可以给你算法
(1) 将1放在最后一行的源码源代网游源码网店中间一列;
(2) 从2开始直到n×n止各数依次按下列规则存放:
按 °方向行走,向右下
每一个数存放的魔方魔方码行比前一个数的行数加1,列数加1
(3) 如果行列范围超出矩阵范围,源码源代则回绕。魔方魔方码
例如1在最后一行,源码源代则2应放在第一行,魔方魔方码列数为中间一列加1;
(4) 如果按上面规则确定的源码源代位置上已有数,或上一个数是魔方魔方码betaflight 源码分析第n行第n列时,
则把下一个数放在上一个数的源码源代上面。
下面是魔方魔方码自动捕鱼源码C++代码,调用此函数,s代表矩阵起始值,如1;n代表矩阵行列数;ma为矩阵数组头地址;调用完只要把ma按照n行n列打印即是结果
void main()
{
int i;
void cube1(int,int,int *);
cout<<"请输入一个整数:";
cin>>i;
cout<<endl;
int *mn=(int*)malloc(i*i*sizeof(int));
if(i%2==1)
cube1(1,i,mn);
}
void cube1(int s,int n,int *ma)
{
int i,j,c,d,e,f;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
ma[i*n+j]=0;
}
c=n-1;d=(n-1)/2;
ma[c*n+d]=s;
for(i=1;i<n*n;i++)
{
if((c>=(n-1))&&(d>=(n-1)))
{
e=c-1;f=d;
}
else if(c>=(n-1))
{
e=0;f=d+1;
}
else if(d>=(n-1))
{
f=0;e=c+1;
}
else if(ma[(c+1)*n+d+1]!=0)
{
e=c-1;f=d;
}
else
{
e=c+1;f=d+1;
}
ma[e*n+f]=ma[c*n+d]+1;
c=e;d=f;
}
}