2024-05-03 05:40:26
不对啊
哪里不对了....
你如果是没有定义数组的话
前面加一句
int[,] arr = { { 1, 2, 3, 4 }, { 6, 7, 8, 9 }, { 10, 11, 12, 13 }, { 14, 15, 16, 17 }, { 3, 56, 24, 1 } };
就好了
这样
using System;
namespace csharpconsole
{
class Program
{
static void Main(string[] args)
{
int[,] arr = { { 1, 2, 3, 4 }, { 6, 7, 8, 9 }, { 10, 11, 12, 13 }, { 14, 15, 16, 17 }, { 3, 56, 24, 1 } };
int odd = 0;
int even = 0;
for (int i = 0; i < 5; i++)
for (int j = 0; j < 4; j++)
if (arr[i,j] % 2 == 0) even++;
else odd++;
Console.WriteLine("偶数有{0}个, 奇数有{1}个", even, odd);
Console.ReadKey();
}
}
}
2024-05-03 05:22:02
不用windows窗体 用控制台应用程序 急~~
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int[,] a = { { 1, 2, 3, 4 }, { 6, 7, 8, 9 }, { 10, 11, 12, 13 }, { 14, 15, 16, 17 }, { 3, 56, 24, 1 } };
int i, j = 0;
int js = 0, os = 0;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 4; j++)
{
if (a[i, j] % 2 == 0)
os++;
else js++;
}
}
Console.WriteLine("偶数个数为" + os.ToString() + "奇数个数为" + js.ToString());
Console.ReadKey();
}
}
}