# Batch output n-Order magic square script

Source: Internet
Author: User
Tags goto

Magic Square is also known as Rubik's Cube, square squares or halls. In a square consisting of a number of neatly arranged numbers, the sum of the numbers of any one row, one longitudinal line, and the diagonal is equal, and a chart of this nature, called Magic Square,

Ancient China called "river Map", "Luo Shu", also known as "vertical and horizontal map." &nbsp; Code as follows: @echo off:start set/p n=please input your odd integer:set/a p=n%%2 if%p% equ 0 echo Input error!&amp;&am P;goto start &nbsp; set/a i=%n% set/a t= (%n%+1)/2 set/a a%t%_%n%=1,temp=1,m=n-1,p=n:repeat set/a p-=1 if%p% LSS 0 go To array for/l%%a on (1 1%m%) do (&nbsp; &nbsp;setlocal enabledelayedexpansion &nbsp; &nbsp;if!t! GTR%n% set/a t=1 &nbsp; &nbsp;if!i! GTR%n% set/a i=1 &nbsp; &nbsp;set/a s=!t!+1,q=!i!+1 &nbsp; &nbsp;if!s! GTR%n% set/a S=1 &nbsp; &nbsp;if!q! GTR%n% set/a q=1 &nbsp; &nbsp;set/a a!s!_!q!=a!t!_!i!+1,t+=1,i+=1 &nbsp; &nbsp;set/a temp+=1 &nbsp; &nbsp;if!temp! Equ%n% (&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set/a temp=1,tmp=a!s!_!q!,q-=1,i-=1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if!q! Equ 0 set/a q=n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set/a a!s!_!q!=tmp+1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto repeat) & nbsp;&nbsp;) Pause:array echo now behold the powerful Magic sqaure^^!: set/a a!t!_!n!=1 for/l%%c in (!n!-1 1 Do (&nbsp; &nbsp;for/l%%d in (1 1!n!) do (&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set/a result=a%%d_% %c &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set/p=!result!&lt;nul &nbsp; &nbsp; &nbsp;) echo. ) Pause&gt;nul
Related Keywords:
Related Article

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD