数字魔方c语言程序,关于数字魔方的问题

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

发个现成的给你.只供参考

/* Note:Your choice is C IDE */

#include "stdio.h"

#include "conio.h"

main()

{

int a[21][21];

int i,j,k,x=1,N,t=0;

textbackground(GREEN);

clrscr();

printf("when program end,enter anykey,close win\n");

loop3:

printf("enter N(N=1~11):");

scanf("%d",&N);

if( N<=0||N>20||(N+2)%2==0)

goto loop3;

/*原始数组 */

for(i=0;i

for(j=0;j

{

a[i][j]=x;

x++;

}

/*数组的初始化*/

for(i=0;i

for(j=0;j

{

a[i][j]=0;

}

/*printf("press any key,GAME star\n\n");*/

/*创建魔方阵*/

j=1;

i=N/2+1;

for(k=1;k<=N*N;k++)

{

i=i-1;

j=j-1;

if((i<0)&&(j<0))

{

i=i+1;

j=j+2;

}

else

{

if(i<0) i=N-1;

if(j<0) j=N-1;

}

if(a[i][j]==0)

{

a[i][j]=k;

}

else

{

i=i+1;

j=j+2;

a[i][j]=k;

}

gotoxy(j*4+24,i*2+5);

printf("%4d",k);

delay(500000);

delay(500000);

delay(500000);

delay(500000);

delay(500000);

}

while(getch()==NULL)

{

t++;

}

}

#include #include #include #include int a[3][3]={1,1,1,1,1,1,1,1,1}; /*INITIALIZE SIX PLANS*/ int b[3][3]={2,2,2,2,2,2,2,2,2}; int c[3][3]={4,4,4,4,4,4,4,4,4}; int d[3][3]={3,3,3,3,3,3,3,3,3}; int e[3][3]={5,5,5,5,5,5,5,5,5}; int f[3][3]={7,7,7,7,7,7,7,7,7}; int top[3][3],front[3][3],side[3][3]; int position=0,temp[3]={0,0,0},new[3][3]; /*POSITION ASSIGN THE ARROW POSITION*/ int sign; main() { int l=60,x=50,y=50,key,count,input=0,errorcode; /*L MEANS THE LENTH OF THE SQUARE,X MEANS THE INITAIL POSITION OF X,Y MEANS THE INITIAL POSITION OF Y*/ int a1[3][3]={1,1,1,1,1,1,1,1,1}; /*INITIALIZE SIX PLANS FOR BACKUP*/ int b1[3][3]={2,2,2,2,2,2,2,2,2}; int c1[3][3]={4,4,4,4,4,4,4,4,4}; int d1[3][3]={3,3,3,3,3,3,3,3,3}; int e1[3][3]={5,5,5,5,5,5,5,5,5}; int f1[3][3]={7,7,7,7,7,7,7,7,7}; int graphdriver=VGA,graphmode=VGAHI; initgraph(&graphdriver,&graphmode,""); errorcode = graphresult(); if (errorcode != grOk) /*MEET ERROR*/ { /*SHOW THE ERROE*/ printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to exit:"); getch(); exit(1); } drawing(x,y,l); /*DRAWING THE BIG SQUARE*/ drawing(x+400,y,l/2); /*DRAWING THE SMALL SQUARE*/ do { sign=position%3; /*COPY DATA TO SHOW*/ copy (&a,&top); copy (&b,&front); copy (&c,&side); color(x,y,l); /*SHOWING THE BIG SQUARE*/ copy (&e,&top); change2(&top,1); copy (&f,&front); change2(&front,2); copy (&d,&side); color(x+400,y,l/2); /*SHOWING THE SMALL SQUARE*/ setcolor(14); arrow(x,y,l); key=bioskey(0); /*READ KEYBORD*/ switch(key) { case 283:printf("Esc"); /*IF INPUT_KEY="ESC" TO EXIT THE PROGRAM*/ goto end; case 20480:setcolor(0); /*IF INPUT_KEY="DOWN" TO CHANGE THE ARROW*/ arrow(x,y,l); if(position==8) position=0; else position=position+1; break; /*IF INPUT_KEY="UP" TO CHANGE THE ARROW*/ case 18432:setcolor(0); arrow(x,y,l); if(position==0) position=8; else position=position-1;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值