小编use*_*053的帖子

魔方计划(C++)

对于那些不熟悉经典魔方算法的人:魔方是一个二维数组(nxn),它包含每个位置中值1和n ^ 2之间的数值.每个值只能出现一次.此外,每行,列和对角线的总和必须相同.输入应该是奇怪的,因为我正在写一个奇怪的方形解决方案.


我已经完成了这个问题,但截至目前它有一个未知的错误(逻辑?输出?),这一直困扰着我过去一小时.输出的值非常不合适.任何帮助将非常感谢:


#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
  int n;

  cout<< "Please enter an odd integer: ";
  cin>>n;

  int MagicSquare[n][n];


  int newRow,
  newCol;

  // Set the indices for the middle of the bottom i
  int i =0 ;
  int j= n / 2;

  // Fill each element of the array using the magic array
  for ( int value = 1; value <= n*n; value++ )
  {
     MagicSquare[i][j] = value;
     // Find the next cell, wrapping around …
Run Code Online (Sandbox Code Playgroud)

c++ magic-square

6
推荐指数
1
解决办法
4万
查看次数

标签 统计

c++ ×1

magic-square ×1