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."   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!&&am P;goto start   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 (   setlocal enabledelayedexpansion    if!t! GTR%n% set/a t=1    if!i! GTR%n% set/a i=1    set/a s=!t!+1,q=!i!+1    if!s! GTR%n% set/a S=1    if!q! GTR%n% set/a q=1    set/a a!s!_!q!=a!t!_!i!+1,t+=1,i+=1    set/a temp+=1    if!temp! Equ%n% (         set/a temp=1,tmp=a!s!_!q!,q-=1,i-=1          if!q! Equ 0 set/a q=n          set/a a!s!_!q!=tmp+1          goto repeat) & nbsp; ) Pause:array echo now behold the powerful Magic sqaure^^!: set/a a!t!_!n!=1 for/l%%c in (!n!-1 1 Do (   for/l%%d in (1 1!n!) do (              set/a result=a%%d_% %c               Set/p=!result!<nul      ) echo. ) Pause>nul

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.