Created
January 18, 2015 16:06
-
-
Save TheZ3ro/518cf77f2ff66ddf551c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
0 1 2 3 4 | |
1 2 3 4 5 | |
2 3 4 5 6 | |
3 4 5 6 7 | |
4 5 6 7 8 | |
--------- | |
0 | |
2 | |
4 | |
6 | |
8 | |
--------- | |
4 | |
4 | |
4 | |
4 | |
4 | |
--------- | |
0 4 | |
2 4 | |
4 4 | |
6 4 | |
8 4 | |
*/ | |
#include <stdio.h> | |
int main(){ | |
int matrix[5][5] = {{}}; | |
for(int i=0;i<5;i++){ | |
for(int j=0;j<5;j++){ | |
matrix[i][j] = j+i; | |
printf("%d ",matrix[i][j]); | |
} | |
printf("\n"); | |
} | |
printf("\n---------\n"); | |
for(int i=0;i<5;i++){ | |
for(int j=0;j<i;j++){ | |
printf(" "); | |
} | |
printf("%d\n",matrix[i][i]); | |
} | |
printf("\n---------\n"); | |
for(int i=4;i>=0;i--){ | |
for(int j=0;j<i;j++){ | |
printf(" "); | |
} | |
printf("%d\n",matrix[i][4-i]); | |
} | |
printf("\n---------\n"); | |
for(int i=0;i<5;i++){ | |
for(int j=0;j<i;j++){ | |
printf(" "); | |
} | |
printf("%d ",matrix[i][i]); | |
for(int j=0;j<5;j++){ | |
if(j+i==4){ | |
printf("%d\n",matrix[i][j]); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment