kcjf.net
当前位置:首页 >> VB编程:有一个4*4的二维数组,请求出对象线上各元素的和 >>

VB编程:有一个4*4的二维数组,请求出对象线上各元素的和

#include void main() { int i,j,sum1=0,sum2=0,a[4][4]; for(i=0;i{ for(j=0;j{ scanf("%d",&a[i][j]); if(i==j) sum1+=a[i][j]; if(i+j==3) sum2+=a[i][j]; } } printf("主对角线元素之和:%d\n",sum1); printf("辅对角线元素之和:%d\n",sum2); } 本回答由提问者推荐

代码:Private Sub Command1_Click() Cls Dim a(3, 3) As Integer, S1 As Integer, S2 As Integer Randomize For i = LBound(a, 1) To UBound(a, 1) For j = LBound(a, 2) To UBound(a, 2) a(i, j) = Int(Rnd * 9 + 1) S1 = S1 + a(i, j) Print a(i, j); Next j Print

dim a(1 to 4,1 to 4) as integer '定义4*4的数组.dim i as bytea(1,1)=4a(1,3)=5for i=1 to 4 a(2,i)=i*2nextfor i=1 to 4 print a(i,1),a(i,2),a(i,3),a(i,4)nexta(4,3)=-2'把这个代码写到 Form_load 事件过程里,运行一下试试.

Option Base 1Private Sub Command1_Click()Dim a(3, 4) As Integer, i As Integer, j As Integer '定义一个二维数组,i循环代表行下标,j循环代表列下标Dim s As Long, ave As Single 's存放数组元素的和值,ave为平均值s = 0For i = 1 To 3 For j =

代码如下: Option Explicit Option Base 1 '声明下标为1 Dim Arr(4, 5) As Integer '声明一个二维数组 Private Sub Command1_Click() Picture1.Cls '清屏 Dim i As Integer, j As Integer '定义两个用于循环的变量 For i = 1 To 4 For j = 1 To 5 Randomize

Dim a, b As Integer For i = 0 To 3 For j = 0 To 3 If i = j Then a = a + x(i, j) If i + j = 3 Then b = b + x(i, j) Next Next 改为 dim a,b as integer for i=0 to 3 a+=x(i,i) b+=x(i,3-i) next 就行了分享

Private Sub Command1_Click() Dim a(0 To 2, 0 To 3) As Integer Dim i, j As Integer Dim sum, mean sum = 0 Randomize Now For i = 0 To 2 For j = 0 To 3 a(i, j) = Int(Rnd() * 100) sum = sum + a(i, j) Next j Next i mean = sum / 3 / 4 Print sum, meanEnd Sub

int i,j,a[4][4];for(i=0;i<4;i++) for(j=0;j<4;j++) scanf("%d",*(a+i)+j); for(i=0;i<4;i++)s+=a[i][i];printf("%d\n",s);s=0;for(i=0;i<4;i++)s+=a[i][3-i];printf("%d\n",s);

long sum = 0 ;//和值定义为long,防止溢出int i,j;//循环参数for(i = 0;i 评论0 0 0

Private Sub Form_Click() Dim a(1 To 3, 1 To 4) As Integer Dim h(1 To 3) As Integer Dim l(1 To 3) As Integer For i = 1 To 3 For j = 1 To 4 a(i, j) = InputBox("请输入第" & i & "行" & "第" & j & "列的值") '给二维数组给元素赋值 Next j Next i

网站首页 | 网站地图
All rights reserved Powered by www.kcjf.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com