【发布时间】:2021-11-22 00:22:36
【问题描述】:
我想将用户自己填写的两个数组的总和添加到一个变量或第三个数组中,然后将其打印出来。这就是我所坚持的:
Console.Write("How many numbers do you want to add: ");
int howmany = Convert.ToInt32(Console.ReadLine());
int[] numarr1 = new int[howmany];
int[] numarr2 = new int[howmany];
int[] res = new int[1];
for (int i = 0; i < numarr1.Length; i++)
{
Console.Write("Input a first number: ");
int a = Convert.ToInt32(Console.ReadLine());
numarr1[i] = a;
}
for(int b = 0; b < numarr2.Length; b++)
{
Console.Write("Input a second number: ");
int a = Convert.ToInt32(Console.ReadLine());
numarr1[b] = a;
}
int result = numarr1 + numarr2;
除了我尝试添加它们的最后一行之外,一切正常。在互联网上,我正在搜索“如何将两个数组的和相加,但我并没有真正找到任何真正解决我问题的东西。
【问题讨论】:
-
这能回答你的问题吗? How to find the sum of an array of numbers
-
@Jazb 我仍然不知道如何添加它们所以没有。
-
求每个数组的和,然后将两个和相加...