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); } 本回答由提问者推荐

利用VB,编写一个3*4的二维数组输入任意整数并且求所有数组元素和及平均值方法为:1、输入头文件和主函数.2、初始化数组并定义变量类型.3、输入i和j.4、输出第i行第j列的元素.5、编译、运行.注意事项:在Visual Basic 6.0中,采用面向对象程序设计方法(Object-Oriented Programming),把程序和数据封装起来作为一个对象,每个对象都是可视的.

代码如下: 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

option explicit private sub command1_click() dim arr(1 to 4, 1 to 4) as long, i as integer, j as integer, sum as long, sum1 as long for i = 1 to 4 for j = 1 to 4 randomize arr(i, j) = int(100 * rnd) + 1'随机生成1-100的整数 sum = sum + arr(i, j) '所有项之和

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

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 就行了分享

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

您好,1.设有如下两组数据: (1)1,3,5,2,4,18,50,25 (2)5,27,30,35,60,41,87,33 编写一个程序,把上面两组数据分别读入两个数组中,然后把两个数组中对应下标的元素相加,即1+5,3+27,……,25+33,并把相应的结果放入第三个数组中,最后

option explicitprivate sub command1_click() dim arr(1 to 4, 1 to 4) as long, i as integer, j as integer, sum as long, sum1 as long for i = 1 to 4 for j = 1 to 4 randomize arr(i, j) =

VB的 Private Sub Form_Click() Dim a(3) As Variant a(0) = Array(45, 30, 26, 48) a(1) = Array(55, 20, 17, 39) a(2) = Array(41, 25, 19, 22) a(3) = Array(31, 18, 22, 10) Dim sum1 As Integer sum1 = 0 Dim i, j As Integer For i = 0 To 3 sum1 = sum1 + a(i)(i) + a(i)(3 - i) Next i Print "左上-右下对角线的数之和为:"; sum1 End Sub

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