hurricanedurza
BAN USERThe problem with the code is that a pointer is having the address of the memory location having the string.so change it it is not authorized ..which we try to do in concatenation.strcat().
- hurricanedurza January 28, 2013This is my code an it works well.
sort the matrix in an array and then map the pattern traversal in it u will come to know about it.
#include<stdio.h>
#include<conio.h>
#include<Windows.h>
int main()
{
int i=0,j=0,k=0,b=0,l=0,m=0,n=0;
int giv[25][25],in[25],out[25];
puts("\nEnter the order of the matrix->");
scanf_s("%d",&m);
puts("Enter the matrix ->");
for(i=0;i<m;i++)
{ for(j=0;j<m;j++)
scanf_s("%d",&giv[i][j]);
puts("");
}
for(i=0;i<m;i++)
{ for(j=0;j<m;j++)
{ in[k]=giv[i][j];
k++;
}
}
system("cls");
puts("\nEntered matix is\n ");
for(i=0;i<m;i++)
{ for(j=0;j<m;j++)
printf("%4d",giv[i][j]);
puts("");
}
b=(m*m)/2;
out[0]=in[b];
j=1;
/*this is the main procedure try to map it using an array of no.s*/
while(l<m)
{ for(k=1;k<=m;k++)
{ n=k;
if(n%2==0)
{
for(i=1;i<=n;i++)
{
out[j]=in[b+m];
j++;
b=b+m;
}
for(i=1;i<=n;i++)
{
out[j]=in[b+1];
j++;
b=b+1;
}l++;
}
if(n%2==1)
{
for(i=1;i<=n;i++)
{
out[j]=in[b-m];
j++;
b=b-m;
}
for(i=1;i<=n;i++)
{ out[j]=in[b-1];
j++;
b=b-1;
}l++;
}
}
}
printf("\noutput is-> ");
printf("%d",out[0]);
for(i=1;i<(m*m);i++)
{ printf("-");
printf("%d",out[i]);
}
_getch();
return 0;
}
Solution will be :-
1)we will obtain all the sets of 3 no.s using combinations of the 4 no.s .which is like generating all the subsets of a given set subjected to size 3 ;
2)we can limit the above generated nos. using dynamic programming .(like sum of all the elements generated should be greater than the largest no in the given set );
3)and the rest is like change making problem in which we will assume change to be generated as each element of set A, using the set generated by permutation.
which involves using recursion and when we get a possible solution we will output it
else no solution is possible;
dude check my answer
- hurricanedurza January 28, 2013the 1 ur givin is not valid