欢迎来到天天文库
浏览记录
ID:37239427
大小:124.50 KB
页数:19页
时间:2019-05-20
《C语言四阶完美幻方》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、//四阶幻方.cpp:Definestheentrypointfortheconsoleapplication./******************************************************操作系统:WindowsXP**编译环境:MicrosoftVisualC++6.0****程序编写:万传华**联系邮箱:wanchuanhua@sina.com******************************************************///求解幻方//x11x12x13x14//x21x22x23x24
2、//x31x32x33x34//x41x42x43x44//由于已知四阶幻方数量很多,总数是880*8=7040,//故在此只求完美幻方//x11+x12+x13+x14=34//x21+x22+x23+x24=34//x31+x32+x33+x34=34//x41+x42+x43+x44=34//x11+x21+x31+x41=34//x12+x22+x32+x42=34//x13+x23+x33+x43=34//x14+x24+x34+x44=34//x11+x22+x33+x44=34//x14+x23+x32+x41=34//还有泛对角线//x21
3、+x32+x43+x14=34//x31+x42+x13+x24=34//x41+x12+x23+x34=34//x11+x24+x33+x42=34//x12+x21+x34+x43=34//x13+x22+x31+x44=34//#include"stdafx.h"#include#include#include#include#includevoidshow(int*M,unsignedrows,unsignedcols){printf("");for(
4、unsignedi=0;ia的情况if(b>a){c=a,a=b,b=c;}do{c=a%b,a=b,b=c;}while(c);returna;};//整数型方程//方程数FCS>1,未知数WZS>1,FCS<=WZS//int*M,每行一个表达式(共FCS行),共WZS+1列(加常数列)voidEquation(int*M,u
5、nsignedFCS,unsignedWZS){unsignedrow,col,i,j,t;int*P,*Q;//用于访问数组,指向当前操作的方程式intx,y,z,k;++WZS;row=0,col=0,P=M;//参考数row,coldo{//寻找非零参考数t=row;Q=P;while(Q[col]==0){++t;Q+=WZS;if(t>=FCS)break;}if(t>=FCS){++col;continue;}if(P!=Q)//交换{for(j=0;j6、/参考数位置:row行,col列//消元for(i=row+1,Q=P+WZS;i7、FCS,P=M+row*WZS;do{col=0;--row;P-=WZS;while(P[col]==0){++col;if(col>=WZS)break;}if(col>=WZS)continue;//简化for(j=0;j1){for(j=0;j8、=row;while(i--)//第i行,i=[0,row){y=
6、/参考数位置:row行,col列//消元for(i=row+1,Q=P+WZS;i7、FCS,P=M+row*WZS;do{col=0;--row;P-=WZS;while(P[col]==0){++col;if(col>=WZS)break;}if(col>=WZS)continue;//简化for(j=0;j1){for(j=0;j8、=row;while(i--)//第i行,i=[0,row){y=
7、FCS,P=M+row*WZS;do{col=0;--row;P-=WZS;while(P[col]==0){++col;if(col>=WZS)break;}if(col>=WZS)continue;//简化for(j=0;j1){for(j=0;j8、=row;while(i--)//第i行,i=[0,row){y=
8、=row;while(i--)//第i行,i=[0,row){y=
此文档下载收益归作者所有