Sorry but i joined late so reply comes in late.

The problem you are talking about is similar to puzzle that comes of nos 1 to 15 and an extra blank is there and you have to arrange it.I am giving you my code it works for that puzzle of nos.

Your task is to manage images instead of numbers

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include"dos.h"
int getkey()
{
union REGS i,o;
while(!kbhit());
i.h.ah=0;
int86(22,&i,&o);
return(o.h.ah);
}
void display();
int a[4][4]={1,4,15,7,8,10,2,11,14,3,6,13,12,9,5,0},bl=15,flag=1;
void main()
{
int t,i,j;
clrscr();
display();
while(flag)
{
t=getkey();
if(t==75)
if(bl%4 != 0)
{
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
if(4*i+j == bl)
{
a[i][j]=a[i][j-1];
bl--;
break;
}
if(j<4)
break;
}
clrscr();
display();
}
if(t==77)
if(bl%4 != 3)
{
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
if(4*i+j == bl)
{
a[i][j]=a[i][j+1];
bl++;
break;
}
if(j<4)
break;
}
clrscr();
display();
}
if(t==72)
if(bl>3)
{
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(4*i+j+4 == bl)
{
a[i+1][j]=a[i][j];
a[i][j]=0;
bl=4*i+j;
break;
}
clrscr();
display();
}
if(t==80)
if(bl<=11)
{
for(i=1;i<4;i++)
{
for(j=0;j<4;j++)
if((4*i+j-4) == bl)
{
a[i-1][j]=a[i][j];
a[i][j]=0;
bl=4*i+j;
break;
}
if(j<4)
break;
}
clrscr();
display();
}
flag=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
if(a[i][j] != 4*i+j+1)
{
flag=1;
break;
}
if(j<4)
break;
}
}
getch();
}
void display()
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
if(4*i+j == bl)
printf(" ");
else
printf("%4d",a[i][j]);
printf("\n");
}
}

this code is compiled on turbo c

i made it some 4 months ago

don't ask how i did it

i don't remember it now either.

😎