/*Input a 3x3 matrix, and output all 2x2 square matrices in it. The rows and columns of the 2x2 matrices may not be adjacent in the original matrix. However, the elemnts in a row (or column) of the 2x2 matrix must appear in the same row (or column) of the original matrix. For each such matrix, also output the sum of its elements Author:rahule@cse.iitk.ac.in */ #include main() { int a[3][3],i1,i2,j1,j2; printf("enter a 3x3 matrix\n"); for(i1=0;i1<3;i1++) //inputs the 3x3 matrix for(j1=0;j1<3;j1++) scanf("%d",&a[i1][j1]); printf("All possible 2x2 matrices that can be generated are,\n"); for(i1=0;i1<3;i1++) //takes 2x2 matrix starting from (0,0),(0,1),(1,0) and (1,1) and prints it togather with its SUM for(i2=0;i2<3;i2++) { if(i1==i2) continue; for(j1=0;j1<3;j1++) //takes 2x2 matrix starting from (0,0),(0,1),(1,0) and (1,1) and prints it togather with its SUM for(j2=0;j2<3;j2++) { if(j1==j2) continue; printf("%d %d\n%d %d\nSUM %d:\n\n",a[i1][j1],a[i1][j2],a[i2][j1],a[i2][j2], a[i1][j1]+a[i1][j2]+a[i2][j1]+a[i2][j2]); } } }