Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/ #include <stdio.h> int main() { int a,b,c,d,e,f,g,h,i,j=1,N,p=0,q=0,r; while(1) { scanf("%d", &N); if(N==0) break; else { j=1;p=0;q=0; int ara[N][N]; i=N; if(N%2==0) r=N/2; else if(N%2==1) r=(N/2)+1; for(c=1; c<=r; c++) { for(a=p; a<i; a++) { for(b=q; b<i; b++) ara[a][b]=j; } j++; p++; q++; i--; } for(g=0; g<N; g++) { for(h=0; h<N; h++) { if(h==0) printf("%3d",ara[g][h]); else printf(" %3d",ara[g][h]); } printf("\n"); } printf("\n"); } } return 0; }
package pp;
ReplyDeleteimport java.util.Scanner;
public class Main {
static Scanner ab = new Scanner(System.in);
public static void main(String[] args) {
int n, i, j;
while (true) {
n = ab.nextInt();
if (n == 0) {
break;
} else {
int k = 0;
int m[][] = new int[n][n];
int num = 1, help = 0, set = n;
for (i = 0; i < (n + 1) / 2; i++) {
for (j = help; j < set; j++) {
m[j][help] = num;
m[help][j] = num;
m[j][set - 1] = num;
m[set - 1][j] = num;
num++;
}
help++;
set--;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
k++;
if (k == n) {
System.out.println(" "+m[i][j]);
k = 0;
} else {
System.out.print(" "+m[i][j]+" ");
}
}
}
System.out.println("");
}
}
}
}
why presentation error ?
:D
DeleteFor your kind information I don,t have any idea about JAVA!!!
:P
ei logic tar code tar kono specific nam ki ache ??
ReplyDeletethanks bro
ReplyDelete