Skip to content

Instantly share code, notes, and snippets.

@TheZ3ro
Created January 18, 2015 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheZ3ro/518cf77f2ff66ddf551c to your computer and use it in GitHub Desktop.
Save TheZ3ro/518cf77f2ff66ddf551c to your computer and use it in GitHub Desktop.
/*
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