using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
const int N = 7;
int[,] dia = new int[N,N];
int count = 0;
for (int i = 0; i < dia.GetLength(0); i++)
{
for (int j = 0; j < dia.GetLength(1); j++)
if (i == j || i + j == N - 1) { dia[i, j] = 1; count++; }
else dia[i, j] = 0;
}
Console.WriteLine(count);
Console.ReadKey();
}
}
}
说明:运行结果为13
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
//const int N = 8;
//int[,] dia = new int[N, N];
//int count = 0;
//for (int i = 0; i < dia.GetLength(0); i++)
//{
// for (int j = 0; j < dia.GetLength(1); j++)
// if (i == j || i + j == N - 1) { dia[i, j] = 1; count++; }
// else dia[i, j] = 0;
//}
//Console.WriteLine(count);
//Console.ReadKey();
}
}
}
说明:运行结果为16